Alerting: Update mute timings provisioning API to support optimistic locking (#88731)
* add version to time-interval models * set time interval fingerprint as version * update to check provided version * delete to check if version is provided in query parameter 'version' * update integration tests * update specs
This commit is contained in:
@@ -527,7 +527,33 @@ func TestMuteTimings(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("should fail to update mute timing if version does not match", func(t *testing.T) {
|
||||
tm := anotherMuteTiming
|
||||
tm.Version = "wrong-version"
|
||||
tm.TimeIntervals = []timeinterval.TimeInterval{
|
||||
{
|
||||
Times: []timeinterval.TimeRange{
|
||||
{
|
||||
StartMinute: 36,
|
||||
EndMinute: 49,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
_, status, body := apiClient.UpdateMuteTimingWithStatus(t, tm)
|
||||
requireStatusCode(t, http.StatusConflict, status, body)
|
||||
var validationError errutil.PublicError
|
||||
assert.NoError(t, json.Unmarshal([]byte(body), &validationError))
|
||||
assert.NotEmpty(t, validationError, validationError.Message)
|
||||
assert.Equal(t, "alerting.notifications.conflict", validationError.MessageID)
|
||||
if t.Failed() {
|
||||
t.Fatalf("response: %s", body)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("should update existing mute timing", func(t *testing.T) {
|
||||
mt, _, _ := apiClient.GetMuteTimingByNameWithStatus(t, anotherMuteTiming.Name)
|
||||
|
||||
anotherMuteTiming.TimeIntervals = []timeinterval.TimeInterval{
|
||||
{
|
||||
Times: []timeinterval.TimeRange{
|
||||
@@ -538,6 +564,7 @@ func TestMuteTimings(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
anotherMuteTiming.Version = mt.Version
|
||||
|
||||
mt, status, body := apiClient.UpdateMuteTimingWithStatus(t, anotherMuteTiming)
|
||||
requireStatusCode(t, http.StatusAccepted, status, body)
|
||||
|
||||
Reference in New Issue
Block a user