Commit 08d9b85f authored by Adam Reese's avatar Adam Reese

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

parent 9484d8d4
......@@ -19,16 +19,11 @@ type ResourceActorFunc func(*resource.Info) error
// Namespace will set the namespace
// Config allows for overiding values from kubectl
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)
//schema, err := f.Validator(true, "")
//if err != nil {
//return err
//}
return perform(f, namespace, reader, createResource)
}
func perform(f *cmdutil.Factory, namespace string, reader io.Reader, fn ResourceActorFunc) error {
r := f.NewBuilder(includeThirdPartyAPIs).
ContinueOnError().
NamespaceParam(namespace).
......
......@@ -4,15 +4,18 @@ import (
"os"
"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"
)
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 {
t.Fatal(err)
}
defer f.Close()
defer input.Close()
results := []*resource.Info{}
......@@ -26,7 +29,12 @@ func TestPerform(t *testing.T) {
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)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment