simplify kubectl testing factory

This commit is contained in:
David Eads
2018-02-22 09:52:10 -05:00
parent 82eeda0885
commit 6047ead2e5
50 changed files with 508 additions and 781 deletions

View File

@@ -67,7 +67,7 @@ func TestApplyExtraArgsFail(t *testing.T) {
buf := bytes.NewBuffer([]byte{})
errBuf := bytes.NewBuffer([]byte{})
f, _ := cmdtesting.NewAPIFactory()
f := cmdtesting.NewTestFactory()
c := NewCmdApply("kubectl", f, buf, errBuf)
if validateApplyArgs(c, []string{"rc"}) == nil {
t.Fatalf("unexpected non-error")
@@ -331,7 +331,7 @@ func TestRunApplyViewLastApplied(t *testing.T) {
},
}
for _, test := range tests {
f, tf := cmdtesting.NewAPIFactory()
tf := cmdtesting.NewTestFactory()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{
@@ -356,7 +356,7 @@ func TestRunApplyViewLastApplied(t *testing.T) {
}),
}
tf.Namespace = "test"
tf.ClientConfig = defaultClientConfig()
tf.ClientConfigVal = defaultClientConfig()
buf, errBuf := bytes.NewBuffer([]byte{}), bytes.NewBuffer([]byte{})
cmdutil.BehaviorOnFatal(func(str string, code int) {
@@ -365,7 +365,7 @@ func TestRunApplyViewLastApplied(t *testing.T) {
}
})
cmd := NewCmdApplyViewLastApplied(f, buf, errBuf)
cmd := NewCmdApplyViewLastApplied(tf, buf, errBuf)
if test.filePath != "" {
cmd.Flags().Set("filename", test.filePath)
}
@@ -388,7 +388,7 @@ func TestApplyObjectWithoutAnnotation(t *testing.T) {
nameRC, rcBytes := readReplicationController(t, filenameRC)
pathRC := "/namespaces/test/replicationcontrollers/" + nameRC
f, tf := cmdtesting.NewAPIFactory()
tf := cmdtesting.NewTestFactory()
tf.UnstructuredClient = &fake.RESTClient{
NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
@@ -406,11 +406,11 @@ func TestApplyObjectWithoutAnnotation(t *testing.T) {
}),
}
tf.Namespace = "test"
tf.ClientConfig = defaultClientConfig()
tf.ClientConfigVal = defaultClientConfig()
buf := bytes.NewBuffer([]byte{})
errBuf := bytes.NewBuffer([]byte{})
cmd := NewCmdApply("kubectl", f, buf, errBuf)
cmd := NewCmdApply("kubectl", tf, buf, errBuf)
cmd.Flags().Set("filename", filenameRC)
cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{})
@@ -432,7 +432,7 @@ func TestApplyObject(t *testing.T) {
pathRC := "/namespaces/test/replicationcontrollers/" + nameRC
for _, fn := range testingOpenAPISchemaFns {
f, tf := cmdtesting.NewAPIFactory()
tf := cmdtesting.NewTestFactory()
tf.UnstructuredClient = &fake.RESTClient{
NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
@@ -455,7 +455,7 @@ func TestApplyObject(t *testing.T) {
buf := bytes.NewBuffer([]byte{})
errBuf := bytes.NewBuffer([]byte{})
cmd := NewCmdApply("kubectl", f, buf, errBuf)
cmd := NewCmdApply("kubectl", tf, buf, errBuf)
cmd.Flags().Set("filename", filenameRC)
cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{})
@@ -493,7 +493,7 @@ func TestApplyObjectOutput(t *testing.T) {
}
for _, fn := range testingOpenAPISchemaFns {
f, tf := cmdtesting.NewAPIFactory()
tf := cmdtesting.NewTestFactory()
tf.UnstructuredClient = &fake.RESTClient{
NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
@@ -516,7 +516,7 @@ func TestApplyObjectOutput(t *testing.T) {
buf := bytes.NewBuffer([]byte{})
errBuf := bytes.NewBuffer([]byte{})
cmd := NewCmdApply("kubectl", f, buf, errBuf)
cmd := NewCmdApply("kubectl", tf, buf, errBuf)
cmd.Flags().Set("filename", filenameRC)
cmd.Flags().Set("output", "yaml")
cmd.Run(cmd, []string{})
@@ -542,7 +542,7 @@ func TestApplyRetry(t *testing.T) {
firstPatch := true
retry := false
getCount := 0
f, tf := cmdtesting.NewAPIFactory()
tf := cmdtesting.NewTestFactory()
tf.UnstructuredClient = &fake.RESTClient{
NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
@@ -574,7 +574,7 @@ func TestApplyRetry(t *testing.T) {
buf := bytes.NewBuffer([]byte{})
errBuf := bytes.NewBuffer([]byte{})
cmd := NewCmdApply("kubectl", f, buf, errBuf)
cmd := NewCmdApply("kubectl", tf, buf, errBuf)
cmd.Flags().Set("filename", filenameRC)
cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{})
@@ -599,7 +599,7 @@ func TestApplyNonExistObject(t *testing.T) {
pathRC := "/namespaces/test/replicationcontrollers"
pathNameRC := pathRC + "/" + nameRC
f, tf := cmdtesting.NewAPIFactory()
tf := cmdtesting.NewTestFactory()
tf.UnstructuredClient = &fake.RESTClient{
NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
@@ -621,7 +621,7 @@ func TestApplyNonExistObject(t *testing.T) {
buf := bytes.NewBuffer([]byte{})
errBuf := bytes.NewBuffer([]byte{})
cmd := NewCmdApply("kubectl", f, buf, errBuf)
cmd := NewCmdApply("kubectl", tf, buf, errBuf)
cmd.Flags().Set("filename", filenameRC)
cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{})
@@ -643,7 +643,7 @@ func TestApplyEmptyPatch(t *testing.T) {
var body []byte
f, tf := cmdtesting.NewAPIFactory()
tf := cmdtesting.NewTestFactory()
tf.UnstructuredClient = &fake.RESTClient{
GroupVersion: schema.GroupVersion{Version: "v1"},
NegotiatedSerializer: unstructuredSerializer,
@@ -674,7 +674,7 @@ func TestApplyEmptyPatch(t *testing.T) {
buf := bytes.NewBuffer([]byte{})
errBuf := bytes.NewBuffer([]byte{})
cmd := NewCmdApply("kubectl", f, buf, errBuf)
cmd := NewCmdApply("kubectl", tf, buf, errBuf)
cmd.Flags().Set("filename", filenameRC)
cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{})
@@ -691,7 +691,7 @@ func TestApplyEmptyPatch(t *testing.T) {
buf = bytes.NewBuffer([]byte{})
errBuf = bytes.NewBuffer([]byte{})
cmd = NewCmdApply("kubectl", f, buf, errBuf)
cmd = NewCmdApply("kubectl", tf, buf, errBuf)
cmd.Flags().Set("filename", filenameRC)
cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{})
@@ -717,7 +717,7 @@ func testApplyMultipleObjects(t *testing.T, asList bool) {
pathSVC := "/namespaces/test/services/" + nameSVC
for _, fn := range testingOpenAPISchemaFns {
f, tf := cmdtesting.NewAPIFactory()
tf := cmdtesting.NewTestFactory()
tf.UnstructuredClient = &fake.RESTClient{
NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
@@ -747,7 +747,7 @@ func testApplyMultipleObjects(t *testing.T, asList bool) {
buf := bytes.NewBuffer([]byte{})
errBuf := bytes.NewBuffer([]byte{})
cmd := NewCmdApply("kubectl", f, buf, errBuf)
cmd := NewCmdApply("kubectl", tf, buf, errBuf)
if asList {
cmd.Flags().Set("filename", filenameRCSVC)
} else {
@@ -800,7 +800,7 @@ func TestApplyNULLPreservation(t *testing.T) {
deploymentBytes := readDeploymentFromFile(t, filenameDeployObjServerside)
for _, fn := range testingOpenAPISchemaFns {
f, tf := cmdtesting.NewAPIFactory()
tf := cmdtesting.NewTestFactory()
tf.UnstructuredClient = &fake.RESTClient{
NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
@@ -844,7 +844,7 @@ func TestApplyNULLPreservation(t *testing.T) {
buf := bytes.NewBuffer([]byte{})
errBuf := bytes.NewBuffer([]byte{})
cmd := NewCmdApply("kubectl", f, buf, errBuf)
cmd := NewCmdApply("kubectl", tf, buf, errBuf)
cmd.Flags().Set("filename", filenameDeployObjClientside)
cmd.Flags().Set("output", "name")
@@ -872,7 +872,7 @@ func TestUnstructuredApply(t *testing.T) {
verifiedPatch := false
for _, fn := range testingOpenAPISchemaFns {
f, tf := cmdtesting.NewAPIFactory()
tf := cmdtesting.NewTestFactory()
tf.UnstructuredClient = &fake.RESTClient{
NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
@@ -907,7 +907,7 @@ func TestUnstructuredApply(t *testing.T) {
buf := bytes.NewBuffer([]byte{})
errBuf := bytes.NewBuffer([]byte{})
cmd := NewCmdApply("kubectl", f, buf, errBuf)
cmd := NewCmdApply("kubectl", tf, buf, errBuf)
cmd.Flags().Set("filename", filenameWidgetClientside)
cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{})
@@ -939,7 +939,7 @@ func TestUnstructuredIdempotentApply(t *testing.T) {
verifiedPatch := false
for _, fn := range testingOpenAPISchemaFns {
f, tf := cmdtesting.NewAPIFactory()
tf := cmdtesting.NewTestFactory()
tf.UnstructuredClient = &fake.RESTClient{
NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
@@ -997,7 +997,7 @@ func TestUnstructuredIdempotentApply(t *testing.T) {
buf := bytes.NewBuffer([]byte{})
errBuf := bytes.NewBuffer([]byte{})
cmd := NewCmdApply("kubectl", f, buf, errBuf)
cmd := NewCmdApply("kubectl", tf, buf, errBuf)
cmd.Flags().Set("filename", filenameWidgetClientside)
cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{})
@@ -1067,7 +1067,7 @@ func TestRunApplySetLastApplied(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
f, tf := cmdtesting.NewAPIFactory()
tf := cmdtesting.NewTestFactory()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{
@@ -1096,7 +1096,7 @@ func TestRunApplySetLastApplied(t *testing.T) {
}),
}
tf.Namespace = "test"
tf.ClientConfig = defaultClientConfig()
tf.ClientConfigVal = defaultClientConfig()
buf, errBuf := bytes.NewBuffer([]byte{}), bytes.NewBuffer([]byte{})
cmdutil.BehaviorOnFatal(func(str string, code int) {
@@ -1105,7 +1105,7 @@ func TestRunApplySetLastApplied(t *testing.T) {
}
})
cmd := NewCmdApplySetLastApplied(f, buf, errBuf)
cmd := NewCmdApplySetLastApplied(tf, buf, errBuf)
cmd.Flags().Set("filename", test.filePath)
cmd.Flags().Set("output", test.output)
cmd.Run(cmd, []string{})
@@ -1159,7 +1159,7 @@ func TestForceApply(t *testing.T) {
for _, fn := range testingOpenAPISchemaFns {
deleted := false
counts := map[string]int{}
f, tf := cmdtesting.NewAPIFactory()
tf := cmdtesting.NewTestFactory()
tf.UnstructuredClient = &fake.RESTClient{
NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
@@ -1219,12 +1219,12 @@ func TestForceApply(t *testing.T) {
}
tf.OpenAPISchemaFunc = fn
tf.Client = tf.UnstructuredClient
tf.ClientConfig = &restclient.Config{}
tf.ClientConfigVal = &restclient.Config{}
tf.Namespace = "test"
buf := bytes.NewBuffer([]byte{})
errBuf := bytes.NewBuffer([]byte{})
cmd := NewCmdApply("kubectl", f, buf, errBuf)
cmd := NewCmdApply("kubectl", tf, buf, errBuf)
cmd.Flags().Set("filename", filenameRC)
cmd.Flags().Set("output", "name")
cmd.Flags().Set("force", "true")