Skip to content

Commit

Permalink
make table driven test more idiomatic
Browse files Browse the repository at this point in the history
Signed-off-by: Ethan Hunter <[email protected]>
  • Loading branch information
Spaceman1701 committed Aug 21, 2024
1 parent 969f274 commit 4f0e5ea
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions silence/silence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ func TestSilenceGCOverTime(t *testing.T) {
s *pb.Silence
expectPresentAfterGc bool
}
type testCase struct {
initialState []silenceEntry
updates []silenceEntry
expectedGCCount int
}

c := clock.NewMock()
now := c.Now().UTC()

Expand All @@ -109,15 +103,22 @@ func TestSilenceGCOverTime(t *testing.T) {
}

// The GC will run with it's clock equal to 1 second after now
cases := map[string]testCase{
"gc does not clean active silences": {
cases := []struct {
name string
initialState []silenceEntry
updates []silenceEntry
expectedGCCount int
}{
{
name: "gc does not clean active silences",
initialState: []silenceEntry{
{s: newSilence("1", now), expectPresentAfterGc: false},
{s: newSilence("2", now.Add(-time.Second)), expectPresentAfterGc: false},
{s: newSilence("3", now.Add(time.Second)), expectPresentAfterGc: true},
},
},
"silences added with Set are handled correctly": {
{
name: "silences added with Set are handled correctly",
initialState: []silenceEntry{
{s: newSilence("1", now), expectPresentAfterGc: false},
},
Expand All @@ -126,7 +127,8 @@ func TestSilenceGCOverTime(t *testing.T) {
{s: newSilence("", now.Add(-time.Second)), expectPresentAfterGc: false},
},
},
"silence update does not leak state": {
{
name: "silence update does not leak state",
initialState: []silenceEntry{
{s: newSilence("1", now), expectPresentAfterGc: false},
},
Expand All @@ -136,8 +138,8 @@ func TestSilenceGCOverTime(t *testing.T) {
},
}

for name, tc := range cases {
t.Run(name, func(t *testing.T) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
silences, err := New(Options{})
require.NoError(t, err)

Expand Down

0 comments on commit 4f0e5ea

Please sign in to comment.