kubens add a short-circuit to bypass API call for tests

Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
Ahmet Alp Balkan 2020-04-29 12:52:08 -07:00
parent 04689f571e
commit 5348d7aa7e
No known key found for this signature in database
GPG Key ID: 441833503E604E2C
2 changed files with 10 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package main
import (
"fmt"
"io"
"os"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -49,6 +50,10 @@ func (op ListOp) Run(stdout, stderr io.Writer) error {
}
func queryNamespaces(kc *kubeconfig.Kubeconfig) ([]string, error) {
if os.Getenv("_MOCK_NAMESPACES") != "" {
return []string{"ns1","ns2"}, nil
}
b, err := kc.Bytes()
if err != nil {
return nil, errors.Wrap(err, "failed to convert in-memory kubeconfig to yaml")

View File

@ -1,8 +1,13 @@
#!/usr/bin/env bats
COMMAND="${COMMAND:-$BATS_TEST_DIRNAME/../kubens}"
# TODO(ahmetb) remove this after bash implementations are deleted
export KUBECTL="$BATS_TEST_DIRNAME/../test/mock-kubectl"
# short-circuit namespace querying in kubens go implementation
export _MOCK_NAMESPACES=1
load common
@test "--help should not fail" {