fix(kube): use a fake client in unit tests

pull/613/head
Adam Reese 9 years ago
parent 9484d8d440
commit 08d9b85f99

@ -19,16 +19,11 @@ type ResourceActorFunc func(*resource.Info) error
// Namespace will set the namespace // Namespace will set the namespace
// Config allows for overiding values from kubectl // Config allows for overiding values from kubectl
func Create(namespace string, reader io.Reader, config clientcmd.ClientConfig) error { func Create(namespace string, reader io.Reader, config clientcmd.ClientConfig) error {
return perform(namespace, reader, createResource, config)
}
func perform(namespace string, reader io.Reader, fn ResourceActorFunc, config clientcmd.ClientConfig) error {
f := cmdutil.NewFactory(config) f := cmdutil.NewFactory(config)
//schema, err := f.Validator(true, "") return perform(f, namespace, reader, createResource)
//if err != nil { }
//return err
//}
func perform(f *cmdutil.Factory, namespace string, reader io.Reader, fn ResourceActorFunc) error {
r := f.NewBuilder(includeThirdPartyAPIs). r := f.NewBuilder(includeThirdPartyAPIs).
ContinueOnError(). ContinueOnError().
NamespaceParam(namespace). NamespaceParam(namespace).

@ -4,15 +4,18 @@ import (
"os" "os"
"testing" "testing"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/resource" "k8s.io/kubernetes/pkg/kubectl/resource"
) )
func TestPerform(t *testing.T) { func TestPerform(t *testing.T) {
f, err := os.Open("./testdata/guestbook-all-in-one.yaml") input, err := os.Open("./testdata/guestbook-all-in-one.yaml")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer f.Close() defer input.Close()
results := []*resource.Info{} results := []*resource.Info{}
@ -26,7 +29,12 @@ func TestPerform(t *testing.T) {
return nil return nil
} }
if err := perform("test", f, fn, nil); err != nil { f := cmdutil.NewFactory(nil)
f.ClientForMapping = func(mapping *meta.RESTMapping) (resource.RESTClient, error) {
return &fake.RESTClient{}, nil
}
if err := perform(f, "test", input, fn); err != nil {
t.Fatalf("Unexpected error: %s", err) t.Fatalf("Unexpected error: %s", err)
} }

Loading…
Cancel
Save