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
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")