@@ -100,6 +100,33 @@ func TestSplittingConfiguration(t *testing.T) {
100100 }
101101}
102102
103+ func TestValidSourceKeys (t * testing.T ) {
104+ assert .Empty (t , validSourceKeys (nil ))
105+ assert .Empty (t , validSourceKeys ([]configuration.Configuration {}))
106+
107+ configs := []configuration.Configuration {{Name : "foo" }}
108+ keys := validSourceKeys (configs )
109+ assert .True (t , keys ["foo" ])
110+ assert .Len (t , keys , 1 )
111+
112+ configs = []configuration.Configuration {{Name : "bar" , Entries : []string {"a" , "b" }}}
113+ keys = validSourceKeys (configs )
114+ assert .True (t , keys ["bar.a" ])
115+ assert .True (t , keys ["bar.b" ])
116+ assert .Len (t , keys , 2 )
117+
118+ configs = []configuration.Configuration {
119+ {Name : "single" },
120+ {Name : "multi" , Entries : []string {"x" , "y" , "z" }},
121+ }
122+ keys = validSourceKeys (configs )
123+ assert .True (t , keys ["single" ])
124+ assert .True (t , keys ["multi.x" ])
125+ assert .True (t , keys ["multi.y" ])
126+ assert .True (t , keys ["multi.z" ])
127+ assert .Len (t , keys , 4 )
128+ }
129+
103130func TestReadConfiguration (t * testing.T ) {
104131 _ , err := readConfiguration ("testdata/does-not.exist" )
105132 assert .NotNil (t , err )
@@ -221,6 +248,41 @@ func TestRunWithRegistrySavesUpdates(t *testing.T) {
221248 assert .Contains (t , string (content ), "1.0.0" )
222249}
223250
251+ func TestRunWithRegistryRemovesStaleEntries (t * testing.T ) {
252+ server , config , tmpDir := setup (t )
253+ defer server .Close ()
254+
255+ registryPath := path .Join (tmpDir , "registry.yaml" )
256+ initialContent := `sources:
257+ http:
258+ kind: http
259+ version: 1.0.0
260+ lastUpdated: "2026-01-01T00:00:00Z"
261+ stale1:
262+ kind: helm
263+ version: v1.0.0
264+ lastUpdated: "2026-01-01T00:00:00Z"
265+ stale2:
266+ kind: git
267+ version: v1.0.0
268+ lastUpdated: "2026-01-01T00:00:00Z"
269+ `
270+ os .WriteFile (registryPath , []byte (initialContent ), 0664 )
271+
272+ updater := NewUpdater (config , tmpDir , tmpDir , registryPath , bytes .NewBuffer ([]byte {}), nil )
273+
274+ err := updater .Run ()
275+ assert .Nil (t , err )
276+
277+ content , err := os .ReadFile (registryPath )
278+ assert .Nil (t , err )
279+
280+ assert .Contains (t , string (content ), "http" )
281+ assert .Contains (t , string (content ), "1.0.0" )
282+ assert .NotContains (t , string (content ), "stale1" )
283+ assert .NotContains (t , string (content ), "stale2" )
284+ }
285+
224286// Test is skipped during unit testing and meant for step-debugging a local check
225287func TestCheckLocal (t * testing.T ) {
226288 output := "../../build/ephemeral/schema"
0 commit comments