From e64dff19d64f7b0e75f7d937ffeae64d96104843 Mon Sep 17 00:00:00 2001 From: Erik Kristensen Date: Mon, 14 Oct 2024 20:04:13 -0600 Subject: [PATCH] test(registry): improve test coverage of panic on circular dependency --- pkg/registry/registry_test.go | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/pkg/registry/registry_test.go b/pkg/registry/registry_test.go index 76ce1b9..32cc663 100644 --- a/pkg/registry/registry_test.go +++ b/pkg/registry/registry_test.go @@ -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() + }) +}