Skip to content

Commit

Permalink
Merge pull request #6446 from ghodss/fix-patch-test
Browse files Browse the repository at this point in the history
Re-enable PATCH integration test for v1beta3
  • Loading branch information
bgrant0607 committed Apr 6, 2015
2 parents 05fd6fe + 5ce15b7 commit 338a51d
Showing 1 changed file with 48 additions and 22 deletions.
70 changes: 48 additions & 22 deletions cmd/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,10 +598,6 @@ func runAtomicPutTest(c *client.Client) {
}

func runPatchTest(c *client.Client) {
if c.APIVersion() != "v1beta1" {
glog.Info("Skipping PATCH tests for non-v1beta1 for now.")
return
}
name := "patchservice"
resource := "services"
svcBody := api.Service{
Expand Down Expand Up @@ -630,31 +626,61 @@ func runPatchTest(c *client.Client) {
glog.Fatalf("Failed creating patchservice: %v", err)
}

patchBodies := map[api.PatchType]struct {
patchBodies := map[string]map[api.PatchType]struct {
AddLabelBody []byte
RemoveLabelBody []byte
RemoveAllLabelsBody []byte
}{
api.JSONPatchType: {
[]byte(`[{"op":"add","path":"/labels","value":{"foo":"bar","baz":"qux"}}]`),
[]byte(`[{"op":"remove","path":"/labels/foo"}]`),
[]byte(`[{"op":"remove","path":"/labels"}]`),
},
api.MergePatchType: {
[]byte(`{"labels":{"foo":"bar","baz":"qux"}}`),
[]byte(`{"labels":{"foo":null}}`),
[]byte(`{"labels":null}`),
"v1beta1": {
api.JSONPatchType: {
[]byte(`[{"op":"add","path":"/labels","value":{"foo":"bar","baz":"qux"}}]`),
[]byte(`[{"op":"remove","path":"/labels/foo"}]`),
[]byte(`[{"op":"remove","path":"/labels"}]`),
},
api.MergePatchType: {
[]byte(`{"labels":{"foo":"bar","baz":"qux"}}`),
[]byte(`{"labels":{"foo":null}}`),
[]byte(`{"labels":null}`),
},
api.StrategicMergePatchType: {
[]byte(`{"labels":{"foo":"bar","baz":"qux"}}`),
[]byte(`{"labels":{"foo":null}}`),
[]byte(`{"labels":{"$patch":"replace"}}`),
},
},
api.StrategicMergePatchType: {
[]byte(`{"labels":{"foo":"bar","baz":"qux"}}`),
[]byte(`{"labels":{"foo":null}}`),
[]byte(`{"labels":{"$patch":"replace"}}`),
"v1beta3": {
api.JSONPatchType: {
[]byte(`[{"op":"add","path":"/metadata/labels","value":{"foo":"bar","baz":"qux"}}]`),
[]byte(`[{"op":"remove","path":"/metadata/labels/foo"}]`),
[]byte(`[{"op":"remove","path":"/metadata/labels"}]`),
},
api.MergePatchType: {
[]byte(`{"metadata":{"labels":{"foo":"bar","baz":"qux"}}}`),
[]byte(`{"metadata":{"labels":{"foo":null}}}`),
[]byte(`{"metadata":{"labels":null}}`),
},
api.StrategicMergePatchType: {
[]byte(`{"metadata":{"labels":{"foo":"bar","baz":"qux"}}}`),
[]byte(`{"metadata":{"labels":{"foo":null}}}`),
[]byte(`{"metadata":{"labels":{"$patch":"replace"}}}`),
},
},
}

for k, v := range patchBodies {
pb := patchBodies[c.APIVersion()]

execPatch := func(pt api.PatchType, body []byte) error {
return c.Patch(pt).
Resource(resource).
Namespace(api.NamespaceDefault).
Name(name).
Body(body).
Do().
Error()
}
for k, v := range pb {
// add label
_, err := c.Patch(k).Resource(resource).Name(name).Body(v.AddLabelBody).Do().Get()
err := execPatch(k, v.AddLabelBody)
if err != nil {
glog.Fatalf("Failed updating patchservice with patch type %s: %v", k, err)
}
Expand All @@ -667,7 +693,7 @@ func runPatchTest(c *client.Client) {
}

// remove one label
_, err = c.Patch(k).Resource(resource).Name(name).Body(v.RemoveLabelBody).Do().Get()
err = execPatch(k, v.RemoveLabelBody)
if err != nil {
glog.Fatalf("Failed updating patchservice with patch type %s: %v", k, err)
}
Expand All @@ -680,7 +706,7 @@ func runPatchTest(c *client.Client) {
}

// remove all labels
_, err = c.Patch(k).Resource(resource).Name(name).Body(v.RemoveAllLabelsBody).Do().Get()
err = execPatch(k, v.RemoveAllLabelsBody)
if err != nil {
glog.Fatalf("Failed updating patchservice with patch type %s: %v", k, err)
}
Expand Down

0 comments on commit 338a51d

Please sign in to comment.