-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: use datemath for notification silence
- Loading branch information
1 parent
dc2b1ec
commit a2d4c63
Showing
7 changed files
with
139 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package notification | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/flanksource/duty/models" | ||
"github.com/google/uuid" | ||
"github.com/samber/lo" | ||
) | ||
|
||
func TestSilenceSaveRequest_Validate(t *testing.T) { | ||
type fields struct { | ||
NotificationSilenceResource models.NotificationSilenceResource | ||
From string | ||
Until string | ||
Description string | ||
from time.Time | ||
until time.Time | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "empty from", | ||
fields: fields{ | ||
NotificationSilenceResource: models.NotificationSilenceResource{}, | ||
From: "", | ||
Until: "now+2d", | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "empty until", | ||
fields: fields{ | ||
NotificationSilenceResource: models.NotificationSilenceResource{}, | ||
From: "now", | ||
Until: "", | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "empty resource", | ||
fields: fields{ | ||
NotificationSilenceResource: models.NotificationSilenceResource{}, | ||
From: "now", | ||
Until: "now+2d", | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "valid", | ||
fields: fields{ | ||
NotificationSilenceResource: models.NotificationSilenceResource{ | ||
ConfigID: lo.ToPtr(uuid.NewString()), | ||
}, | ||
From: "now", | ||
Until: "now+2d", | ||
}, | ||
}, | ||
{ | ||
name: "complete but invalid", | ||
fields: fields{ | ||
NotificationSilenceResource: models.NotificationSilenceResource{ | ||
ConfigID: lo.ToPtr(uuid.NewString()), | ||
}, | ||
From: "now", | ||
Until: "now-1m", | ||
}, | ||
wantErr: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
tr := &SilenceSaveRequest{ | ||
NotificationSilenceResource: tt.fields.NotificationSilenceResource, | ||
From: tt.fields.From, | ||
Until: tt.fields.Until, | ||
Description: tt.fields.Description, | ||
from: tt.fields.from, | ||
until: tt.fields.until, | ||
} | ||
if err := tr.Validate(); (err != nil) != tt.wantErr { | ||
t.Fatalf("SilenceSaveRequest.Validate() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters