Skip to content

Commit

Permalink
test(registry): improve test coverage of panic on circular dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
ekristen committed Oct 15, 2024
1 parent 53c345d commit e64dff1
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions pkg/registry/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,44 @@ func Test_GetLister(t *testing.T) {
l := GetLister("test")
assert.NotNil(t, l)
}

func Test_GetListersV2_CircularDependency(t *testing.T) {
ClearRegistry()

// Note: this is necessary to test the panic when using coverage and multiple tests
defer func() {
if r := recover(); r != nil {
t.Logf("Recovered from panic: %v", r)
}
}()

Register(&Registration{
Name: "A",
Scope: "test",
Lister: TestLister{},
DependsOn: []string{
"B",
"C",
},
})

Register(&Registration{
Name: "B",
Scope: "test",
Lister: TestLister{},
DependsOn: []string{
"A",
"C",
},
})

Register(&Registration{
Name: "C",
Scope: "test",
Lister: TestLister{},
})

assert.Panics(t, func() {
GetListersV2()
})
}

0 comments on commit e64dff1

Please sign in to comment.