@@ -28,9 +28,9 @@ func TestLoadCatalogSources(t *testing.T) {
2828 wantErr bool
2929 }{
3030 {
31- name : "test-catalog-sources" ,
32- args : args {catalogsPath : "testdata/test-catalog-sources.yaml" },
33- want : []string {"catalog1" , "catalog2" },
31+ name : "test-catalog-sources" ,
32+ args : args {catalogsPath : "testdata/test-catalog-sources.yaml" },
33+ want : []string {"catalog1" , "catalog2" },
3434 },
3535 }
3636 for _ , tt := range tests {
@@ -41,6 +41,7 @@ func TestLoadCatalogSources(t *testing.T) {
4141 & MockCatalogArtifactRepository {},
4242 & MockCatalogModelArtifactRepository {},
4343 & MockCatalogMetricsArtifactRepository {},
44+ & MockCatalogSourceRepository {},
4445 & MockPropertyOptionsRepository {},
4546 )
4647 loader := NewLoader (services , []string {tt .args .catalogsPath })
@@ -101,6 +102,7 @@ func TestLoadCatalogSourcesEnabledDisabled(t *testing.T) {
101102 & MockCatalogArtifactRepository {},
102103 & MockCatalogModelArtifactRepository {},
103104 & MockCatalogMetricsArtifactRepository {},
105+ & MockCatalogSourceRepository {},
104106 & MockPropertyOptionsRepository {},
105107 )
106108 loader := NewLoader (services , []string {tt .args .catalogsPath })
@@ -127,6 +129,7 @@ func TestLabelsValidation(t *testing.T) {
127129 & MockCatalogArtifactRepository {},
128130 & MockCatalogModelArtifactRepository {},
129131 & MockCatalogMetricsArtifactRepository {},
132+ & MockCatalogSourceRepository {},
130133 & MockPropertyOptionsRepository {},
131134 )
132135
@@ -257,6 +260,7 @@ func TestCatalogSourceLabelsDefaultToEmptySlice(t *testing.T) {
257260 & MockCatalogArtifactRepository {},
258261 & MockCatalogModelArtifactRepository {},
259262 & MockCatalogMetricsArtifactRepository {},
263+ & MockCatalogSourceRepository {},
260264 & MockPropertyOptionsRepository {},
261265 )
262266 loader := NewLoader (services , []string {tt .args .catalogsPath })
@@ -295,6 +299,7 @@ func TestLoadCatalogSourcesWithMockRepositories(t *testing.T) {
295299 mockArtifactRepo ,
296300 mockModelArtifactRepo ,
297301 mockMetricsArtifactRepo ,
302+ & MockCatalogSourceRepository {},
298303 & MockPropertyOptionsRepository {},
299304 )
300305
@@ -424,6 +429,7 @@ func TestLoadCatalogSourcesWithRepositoryErrors(t *testing.T) {
424429 mockArtifactRepo ,
425430 mockModelArtifactRepo ,
426431 mockMetricsArtifactRepo ,
432+ & MockCatalogSourceRepository {},
427433 & MockPropertyOptionsRepository {},
428434 )
429435
@@ -501,6 +507,7 @@ func TestLoadCatalogSourcesWithNilEnabled(t *testing.T) {
501507 mockArtifactRepo ,
502508 mockModelArtifactRepo ,
503509 mockMetricsArtifactRepo ,
510+ & MockCatalogSourceRepository {},
504511 & MockPropertyOptionsRepository {},
505512 )
506513
@@ -944,6 +951,58 @@ func (m *MockPropertyOptionsRepository) SetMockOptions(t dbmodels.PropertyOption
944951 m.MockOptions [t ][typeID ] = options
945952}
946953
954+ // MockCatalogSourceRepository mocks the CatalogSourceRepository interface.
955+ type MockCatalogSourceRepository struct {
956+ Sources []dbmodels.CatalogSource
957+ }
958+
959+ func (m * MockCatalogSourceRepository ) GetBySourceID (sourceID string ) (dbmodels.CatalogSource , error ) {
960+ for _ , s := range m .Sources {
961+ if attrs := s .GetAttributes (); attrs != nil && attrs .Name != nil && * attrs .Name == sourceID {
962+ return s , nil
963+ }
964+ }
965+ return nil , nil
966+ }
967+
968+ func (m * MockCatalogSourceRepository ) Save (source dbmodels.CatalogSource ) (dbmodels.CatalogSource , error ) {
969+ m .Sources = append (m .Sources , source )
970+ return source , nil
971+ }
972+
973+ func (m * MockCatalogSourceRepository ) Delete (sourceID string ) error {
974+ return nil
975+ }
976+
977+ func (m * MockCatalogSourceRepository ) GetAll () ([]dbmodels.CatalogSource , error ) {
978+ return m .Sources , nil
979+ }
980+
981+ func (m * MockCatalogSourceRepository ) GetAllStatuses () (map [string ]dbmodels.SourceStatus , error ) {
982+ result := make (map [string ]dbmodels.SourceStatus )
983+ for _ , source := range m .Sources {
984+ if attrs := source .GetAttributes (); attrs != nil && attrs .Name != nil {
985+ status := dbmodels.SourceStatus {}
986+ if props := source .GetProperties (); props != nil {
987+ for _ , prop := range * props {
988+ switch prop .Name {
989+ case "status" :
990+ if prop .StringValue != nil {
991+ status .Status = * prop .StringValue
992+ }
993+ case "error" :
994+ if prop .StringValue != nil {
995+ status .Error = * prop .StringValue
996+ }
997+ }
998+ }
999+ }
1000+ result [* attrs .Name ] = status
1001+ }
1002+ }
1003+ return result , nil
1004+ }
1005+
9471006func TestAPIProviderGetPerformanceArtifacts (t * testing.T ) {
9481007 // This test verifies that the APIProvider interface has GetPerformanceArtifacts method
9491008 // The actual implementation is tested in db_catalog_test.go
@@ -954,6 +1013,7 @@ func TestAPIProviderGetPerformanceArtifacts(t *testing.T) {
9541013 & MockCatalogArtifactRepository {},
9551014 & MockCatalogModelArtifactRepository {},
9561015 & MockCatalogMetricsArtifactRepository {},
1016+ & MockCatalogSourceRepository {},
9571017 & MockPropertyOptionsRepository {},
9581018 )
9591019 provider := NewDBCatalog (services , nil )
@@ -981,6 +1041,7 @@ func TestAPIProviderInterface(t *testing.T) {
9811041 & MockCatalogArtifactRepository {},
9821042 & MockCatalogModelArtifactRepository {},
9831043 & MockCatalogMetricsArtifactRepository {},
1044+ & MockCatalogSourceRepository {},
9841045 & MockPropertyOptionsRepository {},
9851046 )
9861047 var provider APIProvider = NewDBCatalog (services , nil )
0 commit comments