Skip to content

Commit ebeafda

Browse files
committed
Set tektonhub as the default catalog type for custom Hub URLs
When a custom hub URL is configured, default the catalog type to TektonHubType instead of ArtifactHubType. Signed-off-by: Shiv Verma <[email protected]>
1 parent 4d75ddc commit ebeafda

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

pkg/params/settings/default.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ func getHubCatalogs(logger *zap.SugaredLogger, catalogs *sync.Map, config map[st
1919
}
2020

2121
if hubType, ok := config[HubCatalogTypeKey]; !ok || hubType == "" {
22-
config[HubCatalogTypeKey] = hubtypes.ArtifactHubType
22+
if hubURL, ok := config[HubURLKey]; !ok || hubURL != ArtifactHubURLDefaultValue {
23+
config[HubCatalogTypeKey] = hubtypes.TektonHubType
24+
} else {
25+
config[HubCatalogTypeKey] = hubtypes.ArtifactHubType
26+
}
2327
} else if hubType != hubtypes.ArtifactHubType && hubType != hubtypes.TektonHubType {
2428
logger.Warnf("CONFIG: invalid hub type %s, defaulting to %s", hubType, hubtypes.ArtifactHubType)
2529
config[HubCatalogTypeKey] = hubtypes.ArtifactHubType

pkg/params/settings/default_test.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"sync"
55
"testing"
66

7+
hubtypes "github.com/openshift-pipelines/pipelines-as-code/pkg/hub/vars"
78
"go.uber.org/zap"
89
zapobserver "go.uber.org/zap/zaptest/observer"
910
"gotest.tools/v3/assert"
@@ -18,11 +19,12 @@ func TestGetCatalogHub(t *testing.T) {
1819
Name: "tekton",
1920
})
2021
tests := []struct {
21-
name string
22-
config map[string]string
23-
numCatalogs int
24-
wantLog string
25-
hubCatalogs *sync.Map
22+
name string
23+
config map[string]string
24+
numCatalogs int
25+
wantLog string
26+
hubCatalogs *sync.Map
27+
wantDefaultType string
2628
}{
2729
{
2830
name: "good/default catalog",
@@ -141,6 +143,15 @@ func TestGetCatalogHub(t *testing.T) {
141143
hubCatalogs: &sync.Map{},
142144
wantLog: `CONFIG: invalid hub type invalid, defaulting to artifacthub`,
143145
},
146+
{
147+
name: "custom hub URL defaults to TektonHubType",
148+
config: map[string]string{
149+
HubURLKey: "https://custom-tekton-hub.example.com",
150+
},
151+
numCatalogs: 1,
152+
hubCatalogs: &sync.Map{},
153+
wantDefaultType: hubtypes.TektonHubType,
154+
},
144155
}
145156
for _, tt := range tests {
146157
t.Run(tt.name, func(t *testing.T) {
@@ -159,6 +170,13 @@ func TestGetCatalogHub(t *testing.T) {
159170
if tt.wantLog != "" {
160171
assert.Assert(t, len(catcher.FilterMessageSnippet(tt.wantLog).TakeAll()) > 0, "could not find log message: got ", catcher)
161172
}
173+
if tt.wantDefaultType != "" {
174+
value, ok := catalogs.Load("default")
175+
assert.Assert(t, ok, "default catalog should exist")
176+
defaultCatalog, ok := value.(HubCatalog)
177+
assert.Assert(t, ok, "default catalog should be HubCatalog type")
178+
assert.Equal(t, defaultCatalog.Type, tt.wantDefaultType)
179+
}
162180
cmp.Equal(catalogs, tt.hubCatalogs)
163181
})
164182
}

0 commit comments

Comments
 (0)