Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-enable PATCH integration test for v1beta3 #6446

Merged
merged 1 commit into from
Apr 6, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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