Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Commit

Permalink
fix: if app has no subscriptions, then nothing to process (#174)
Browse files Browse the repository at this point in the history
fix: if app has no subscriptions, then nothing to process (#174)
  • Loading branch information
mayzhang2000 authored and alexmt committed Feb 17, 2021
1 parent 9928342 commit 8b5154e
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
26 changes: 25 additions & 1 deletion controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ func (c *notificationController) processQueueItem() (processNext bool) {
logEntry.Errorf("Failed to process: %v", err)
return
}
if !reflect.DeepEqual(app.GetAnnotations(), appCopy.GetAnnotations()) {

if !isTheSame(app.GetAnnotations(), appCopy.GetAnnotations()) {
annotationsPatch := make(map[string]interface{})
for k, v := range appCopy.GetAnnotations() {
annotationsPatch[k] = v
Expand Down Expand Up @@ -376,3 +377,26 @@ func (c *notificationController) processQueueItem() (processNext bool) {

return
}

func isTheSame(appAnnotations, appCopyAnnotations map[string]string) bool {
if appAnnotations == nil {
if appCopyAnnotations == nil {
return true
}
if len(appCopyAnnotations) == 0 {
return true
} else {
return false
}
}

if appCopyAnnotations == nil {
if len(appAnnotations) == 0 {
return true
} else {
return false
}
}

return reflect.DeepEqual(appAnnotations, appCopyAnnotations)
}
62 changes: 62 additions & 0 deletions controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,65 @@ var testsAppSyncStatusRefreshed = map[string]struct {
},
}, result: false},
}

func TestAnnotationIsTheSame(t *testing.T) {
t.Run("same", func(t *testing.T) {
app1 := NewApp("test", WithAnnotations(map[string]string{
subscriptions.SubscribeAnnotationKey("my-trigger", "mock"): "recipient",
}))
app2 := NewApp("test", WithAnnotations(map[string]string{
subscriptions.SubscribeAnnotationKey("my-trigger", "mock"): "recipient",
}))
assert.True(t, isTheSame(app1.GetAnnotations(), app2.GetAnnotations()))
})

t.Run("same-nil-nil", func(t *testing.T) {
app1 := NewApp("test", WithAnnotations(nil))
app2 := NewApp("test", WithAnnotations(nil))
assert.True(t, isTheSame(app1.GetAnnotations(), app2.GetAnnotations()))
})

t.Run("same-nil-emptyMap", func(t *testing.T) {
app1 := NewApp("test", WithAnnotations(nil))
app2 := NewApp("test", WithAnnotations(map[string]string{}))
assert.True(t, isTheSame(app1.GetAnnotations(), app2.GetAnnotations()))
})

t.Run("same-emptyMap-nil", func(t *testing.T) {
app1 := NewApp("test", WithAnnotations(map[string]string{}))
app2 := NewApp("test", WithAnnotations(nil))
assert.True(t, isTheSame(app1.GetAnnotations(), app2.GetAnnotations()))
})

t.Run("same-emptyMap-emptyMap", func(t *testing.T) {
app1 := NewApp("test", WithAnnotations(map[string]string{}))
app2 := NewApp("test", WithAnnotations(map[string]string{}))
assert.True(t, isTheSame(app1.GetAnnotations(), app2.GetAnnotations()))
})

t.Run("notSame-nil-map", func(t *testing.T) {
app1 := NewApp("test", WithAnnotations(nil))
app2 := NewApp("test", WithAnnotations(map[string]string{
subscriptions.SubscribeAnnotationKey("my-trigger", "mock"): "recipient",
}))
assert.False(t, isTheSame(app1.GetAnnotations(), app2.GetAnnotations()))
})

t.Run("notSame-map-nil", func(t *testing.T) {
app1 := NewApp("test", WithAnnotations(map[string]string{
subscriptions.SubscribeAnnotationKey("my-trigger", "mock"): "recipient",
}))
app2 := NewApp("test", WithAnnotations(nil))
assert.False(t, isTheSame(app1.GetAnnotations(), app2.GetAnnotations()))
})

t.Run("notSame-map-map", func(t *testing.T) {
app1 := NewApp("test", WithAnnotations(map[string]string{
subscriptions.SubscribeAnnotationKey("my-trigger", "mock"): "recipient",
}))
app2 := NewApp("test", WithAnnotations(map[string]string{
subscriptions.SubscribeAnnotationKey("my-trigger", "mock"): "recipient2",
}))
assert.False(t, isTheSame(app1.GetAnnotations(), app2.GetAnnotations()))
})
}

0 comments on commit 8b5154e

Please sign in to comment.