Skip to content

Commit

Permalink
added testcase for skipping update event notification on invalid upda…
Browse files Browse the repository at this point in the history
…teSettings (#403)


##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug fix Pull Request
##### SUMMARY
<!--- Describe the change, including rationale and design decisions -->
Added skip update event test case that should be skipped if invalid Fields are provided in UpdateSettings test config.
<!---
If you are fixing an existing issue, please include "Fixes #nnn" in your
PR comment; and describe briefly what the change does.
-->
<!--- Please list dependencies added with your change also -->
Fixes test case - Validate that update events are skipped when invalid fields are passed in updateSetting (e.g status.invalid for Pod) #341
  • Loading branch information
akankshakumari393 authored Oct 7, 2020
1 parent 3ff3612 commit d3c0db0
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion test/e2e/notifier/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func (c *context) testUpdateResource(t *testing.T) {
func (c *context) Run(t *testing.T) {
t.Run("update resource", c.testUpdateResource)
t.Run("skip update event", c.testSKipUpdateEvent)
t.Run("skip update event for wrong setting", c.testSkipWrongSetting)
}

// E2ETests runs create notification tests
Expand Down Expand Up @@ -173,7 +174,8 @@ func (c *context) testSKipUpdateEvent(t *testing.T) {
// update operation not allowed for namespaces in test_config so event should be skipped
GVR: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "namespaces"},
Kind: "Namespace",
Specs: &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "abc"}}},
Specs: &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "abc"}},
},
}

for name, test := range tests {
Expand All @@ -194,3 +196,59 @@ func (c *context) testSKipUpdateEvent(t *testing.T) {
// Resetting original configuration as per test_config
utils.AllowedEventKindsMap[utils.EventKind{Resource: "v1/pods", Namespace: "all", EventType: "update"}] = true
}

func (c *context) testSkipWrongSetting(t *testing.T) {
// test scenarios
tests := map[string]testutils.UpdateObjects{
"skip update event for wrong updateSettings value": {
// update event given with wrong value of updateSettings which doesn't exist would be skipped
GVR: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"},
Kind: "Pod",
Namespace: "test",
Specs: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "test-pod-update-skip"}, Spec: v1.PodSpec{Containers: []v1.Container{{Name: "test-pod-container", Image: "tomcat:9.0.34"}}}},
Patch: []byte(`{
"apiVersion": "v1",
"kind": "Pod",
"metadata": {
"name": "test-pod-update-skip",
"namespace": "test"
},
"spec": {
"containers": [
{
"name": "test-pod-container",
"image": "tomcat:8.0"
}
]
}
}
`),
// adding wrong field
UpdateSetting: config.UpdateSetting{Fields: []string{"spec.invalid"}, IncludeDiff: true},
// diff calcuted should be empty because of error
Diff: "",
},
}

for name, test := range tests {
t.Run(name, func(t *testing.T) {
resource := utils.GVRToString(test.GVR)
// checking if update operation is true
isAllowed := utils.AllowedEventKindsMap[utils.EventKind{
Resource: resource,
Namespace: "all",
EventType: config.UpdateEvent}] ||
utils.AllowedEventKindsMap[utils.EventKind{
Resource: resource,
Namespace: test.Namespace,
EventType: config.UpdateEvent}]
assert.Equal(t, isAllowed, true)
// modifying the update setting value as per testcases
utils.AllowedUpdateEventsMap[utils.KindNS{Resource: "v1/pods", Namespace: "all"}] = test.UpdateSetting
// getting the updated and old object
oldObj, newObj := testutils.UpdateResource(t, test)
updateMsg := utils.Diff(oldObj.Object, newObj.Object, test.UpdateSetting)
assert.Equal(t, test.Diff, updateMsg)
})
}
}

0 comments on commit d3c0db0

Please sign in to comment.