Adding delete scenario in conformance test
@@ -33,6 +33,8 @@ const (
v1 = "1.0.0"
defaultMaxReadDuration = 30 * time.Second
defaultWaitDuration = 5 * time.Second
+ setOperation = "set"
+ deleteOperation = "del"
)
type TestConfig struct {
@@ -114,6 +116,9 @@ func updateAwaitingMessages(awaitingMessages map[string]map[string]struct{}, upd
}
func getStringItem(item *configuration.Item) string {
+ if item == nil {
+ return ""
+ }
jsonItem, err := json.Marshal(*item)
if err != nil {
panic(err)
@@ -260,9 +265,24 @@ func ConformanceTests(t *testing.T, props map[string]string, store configuration
//Only Subscriber 3 should receive these updates
updateAwaitingMessages(awaitingMessages3, newValues)
- verifyMessagesReceived(t, processedC1, awaitingMessages1)
- verifyMessagesReceived(t, processedC2, awaitingMessages2)
- verifyMessagesReceived(t, processedC3, awaitingMessages3)
+ verifyMessagesReceived(t, setOperation, processedC1, awaitingMessages1)
+ verifyMessagesReceived(t, setOperation, processedC2, awaitingMessages2)
+ verifyMessagesReceived(t, setOperation, processedC3, awaitingMessages3)
+ })
+
+ t.Run("delete keys and verify messages received", func(t *testing.T) {
+ // Delete initValues2
+ errDelete := updater.DeleteKey(getKeys(initValues2))
+ assert.NoError(t, errDelete, "expected no error on updating keys")
+ for k := range initValues2 {
+ initValues2[k] = nil
+ }
+ //Only Subscriber 2 and 3 should receive thse updates
+ updateAwaitingMessages(awaitingMessages2, initValues2)
+ updateAwaitingMessages(awaitingMessages3, initValues2)
+
+ verifyMessagesReceived(t, deleteOperation, processedC2, awaitingMessages2)
+ verifyMessagesReceived(t, deleteOperation, processedC3, awaitingMessages3)
})
}
@@ -285,8 +305,8 @@ func ConformanceTests(t *testing.T, props map[string]string, store configuration
updateAwaitingMessages(awaitingMessages2, initValues1)
updateAwaitingMessages(awaitingMessages3, initValues1)
- verifyMessagesReceived(t, processedC2, awaitingMessages2)
- verifyMessagesReceived(t, processedC3, awaitingMessages3)
+ verifyMessagesReceived(t, setOperation, processedC2, awaitingMessages2)
+ verifyMessagesReceived(t, setOperation, processedC3, awaitingMessages3)
verifyNoMessagesReceived(t, processedC1)
})
@@ -307,7 +327,7 @@ func ConformanceTests(t *testing.T, props map[string]string, store configuration
updateAwaitingMessages(awaitingMessages3, initValues1)
- verifyMessagesReceived(t, processedC3, awaitingMessages3)
+ verifyMessagesReceived(t, setOperation, processedC3, awaitingMessages3)
verifyNoMessagesReceived(t, processedC2)
})
@@ -343,12 +363,14 @@ func verifyNoMessagesReceived(t *testing.T, processedChan chan *configuration.Up
}
}
}
-func verifyMessagesReceived(t *testing.T, processedChan chan *configuration.UpdateEvent, awaitingMessages map[string]map[string]struct{}) {
+
+func verifyMessagesReceived(t *testing.T, operation string, processedChan chan *configuration.UpdateEvent, awaitingMessages map[string]map[string]struct{}) {
waiting := true
timeout := time.After(defaultMaxReadDuration)
for waiting {
select {
case processed := <-processedChan:
+ assert.Equal(t, operation, processed.Operation)
for key, receivedItem := range processed.Items {
items, keyExists := awaitingMessages[key]
assert.True(t, keyExists)
