@@ -600,6 +600,49 @@ func TestListServersCatalogNotFound(t *testing.T) {
600600 assert .Contains (t , err .Error (), "failed to get catalog" )
601601}
602602
603+ func TestListServersNormalizesCatalogRef (t * testing.T ) {
604+ dao := setupTestDB (t )
605+ ctx := t .Context ()
606+
607+ // Create a catalog with a normalized reference (what the db would store)
608+ catalogObj := Catalog {
609+ Ref : "test/catalog:latest" ,
610+ CatalogArtifact : CatalogArtifact {
611+ Title : "Test Catalog" ,
612+ Servers : []Server {
613+ {
614+ Type : workingset .ServerTypeImage ,
615+ Image : "docker/server1:v1" ,
616+ Snapshot : & workingset.ServerSnapshot {
617+ Server : catalog.Server {
618+ Name : "my-server" ,
619+ },
620+ },
621+ },
622+ },
623+ },
624+ }
625+
626+ dbCat , err := catalogObj .ToDb ()
627+ require .NoError (t , err )
628+ err = dao .UpsertCatalog (ctx , dbCat )
629+ require .NoError (t , err )
630+
631+ // Query with a non-normalized reference (without :latest tag)
632+ // This should still find the catalog because the code normalizes the ref
633+ output := captureStdout (t , func () {
634+ err := ListServers (ctx , dao , "test/catalog" , []string {}, workingset .OutputFormatJSON )
635+ require .NoError (t , err )
636+ })
637+
638+ var result map [string ]any
639+ err = json .Unmarshal ([]byte (output ), & result )
640+ require .NoError (t , err )
641+
642+ servers := result ["servers" ].([]any )
643+ assert .Len (t , servers , 1 )
644+ }
645+
603646func TestListServersYAMLFormat (t * testing.T ) {
604647 dao := setupTestDB (t )
605648 ctx := t .Context ()
0 commit comments