From 17aae4bfe0506bea9819472560f58dfbe905c1f8 Mon Sep 17 00:00:00 2001 From: Piyush Garg Date: Wed, 5 Jun 2024 20:07:52 +0530 Subject: [PATCH] Refactor configutil and fix bug with catalog parsing This will refactor configutil to pass the validators in sync config function so that defaulting and validation can be performed separately default validators are exposed to be used by deps catalog parsing was broken as soon as it find the other key for same catalog so fixed that refactored internal catalog parsing to have index data in map to convert the strut back to configmap added utility to convert struct back to configmap to be used by deps and added unit tests --- hack/dev/kind/install.sh | 2 + pkg/cmd/tknpac/resolve/resolve.go | 2 +- pkg/consoleui/custom.go | 2 +- pkg/consoleui/custom_test.go | 2 +- pkg/hub/get_test.go | 12 +- pkg/matcher/annotation_tasks_install_test.go | 24 +-- pkg/params/info/info.go | 2 +- pkg/params/info/info_test.go | 2 +- pkg/params/settings/config.go | 34 ++-- pkg/params/settings/config_test.go | 4 +- pkg/params/settings/convert.go | 65 ++++++ pkg/params/settings/convert_test.go | 192 ++++++++++++++++++ pkg/params/settings/default.go | 24 +-- pkg/params/settings/default_test.go | 19 +- pkg/pipelineascode/pipelineascode_test.go | 12 +- .../pipelinerun_remote_task_annotations.yaml | 4 +- 16 files changed, 336 insertions(+), 66 deletions(-) create mode 100644 pkg/params/settings/convert.go create mode 100644 pkg/params/settings/convert_test.go diff --git a/hack/dev/kind/install.sh b/hack/dev/kind/install.sh index bd40d12a6..8407bef86 100755 --- a/hack/dev/kind/install.sh +++ b/hack/dev/kind/install.sh @@ -185,6 +185,8 @@ function configure_pac() { kubectl patch configmap -n pipelines-as-code -p "{\"data\":{\"tekton-dashboard-url\": \"http://dashboard.${DOMAIN_NAME}\"}}" --type merge pipelines-as-code # add custom catalog so we can use it in e2e, this will points to the normal upstream hub so we can easily use it kubectl patch configmap -n pipelines-as-code -p '{"data":{"catalog-1-id": "custom", "catalog-1-name": "tekton", "catalog-1-url": "https://api.hub.tekton.dev/v1"}}' --type merge pipelines-as-code + # add one more custom catalog so we can use it in e2e for multiple catalog support, this will points to the normal upstream hub so we can easily use it + kubectl patch configmap -n pipelines-as-code -p '{"data":{"catalog-2-id": "custom2", "catalog-2-name": "tekton", "catalog-2-url": "https://api.hub.tekton.dev/v1"}}' --type merge pipelines-as-code set +x if [[ -n ${PAC_PASS_SECRET_FOLDER} ]]; then echo "Installing PAC secrets" diff --git a/pkg/cmd/tknpac/resolve/resolve.go b/pkg/cmd/tknpac/resolve/resolve.go index a8f711018..716b9c214 100644 --- a/pkg/cmd/tknpac/resolve/resolve.go +++ b/pkg/cmd/tknpac/resolve/resolve.go @@ -104,7 +104,7 @@ func Command(run *params.Run, streams *cli.IOStreams) *cobra.Command { return fmt.Errorf("you need to at least specify a file with -f") } - if err := settings.SyncConfig(run.Clients.Log, &run.Info.Pac.Settings, map[string]string{}); err != nil { + if err := settings.SyncConfig(run.Clients.Log, &run.Info.Pac.Settings, map[string]string{}, settings.DefaultValidators()); err != nil { return err } diff --git a/pkg/consoleui/custom.go b/pkg/consoleui/custom.go index 26b052cb2..733c3f8fc 100644 --- a/pkg/consoleui/custom.go +++ b/pkg/consoleui/custom.go @@ -29,7 +29,7 @@ func NewCustomConsole(pacInfo *info.PacOpts) *CustomConsole { func (o *CustomConsole) GetName() string { if o.pacInfo.CustomConsoleName == "" { - return "Not configured" + return fmt.Sprintf("https://url.setting.%s.is.not.configured", settings.CustomConsoleNameKey) } return o.pacInfo.CustomConsoleName } diff --git a/pkg/consoleui/custom_test.go b/pkg/consoleui/custom_test.go index f0476a8f0..2cc124e95 100644 --- a/pkg/consoleui/custom_test.go +++ b/pkg/consoleui/custom_test.go @@ -102,7 +102,7 @@ func TestCustomBad(t *testing.T) { Name: "pr", }, } - assert.Assert(t, strings.Contains(c.GetName(), "Not configured")) + assert.Assert(t, strings.Contains(c.GetName(), "is.not.configured")) assert.Assert(t, strings.Contains(c.URL(), "is.not.configured")) assert.Assert(t, strings.Contains(c.DetailURL(pr), "is.not.configured")) assert.Assert(t, strings.Contains(c.TaskLogURL(pr, nil), "is.not.configured")) diff --git a/pkg/hub/get_test.go b/pkg/hub/get_test.go index 5e1d50ab4..4b08045d9 100644 --- a/pkg/hub/get_test.go +++ b/pkg/hub/get_test.go @@ -20,15 +20,15 @@ func TestGetTask(t *testing.T) { var hubCatalogs sync.Map hubCatalogs.Store( "default", settings.HubCatalog{ - ID: "default", - URL: testHubURL, - Name: testCatalogHubName, + Index: "default", + URL: testHubURL, + Name: testCatalogHubName, }) hubCatalogs.Store( "anotherHub", settings.HubCatalog{ - ID: "anotherHub", - URL: testHubURL, - Name: testCatalogHubName, + Index: "1", + URL: testHubURL, + Name: testCatalogHubName, }) tests := []struct { name string diff --git a/pkg/matcher/annotation_tasks_install_test.go b/pkg/matcher/annotation_tasks_install_test.go index 8edc69a96..1e395cf03 100644 --- a/pkg/matcher/annotation_tasks_install_test.go +++ b/pkg/matcher/annotation_tasks_install_test.go @@ -50,15 +50,15 @@ func TestRemoteTasksGetTaskFromAnnotations(t *testing.T) { var hubCatalogs sync.Map hubCatalogs.Store( "default", settings.HubCatalog{ - ID: "default", - URL: testHubURL, - Name: testCatalogHubName, + Index: "default", + URL: testHubURL, + Name: testCatalogHubName, }) hubCatalogs.Store( "anotherHub", settings.HubCatalog{ - ID: "anotherHub", - URL: testHubURL, - Name: testCatalogHubName, + Index: "1", + URL: testHubURL, + Name: testCatalogHubName, }) tests := []struct { annotations map[string]string @@ -304,15 +304,15 @@ func TestGetPipelineFromAnnotations(t *testing.T) { var hubCatalogs sync.Map hubCatalogs.Store( "default", settings.HubCatalog{ - ID: "default", - URL: testHubURL, - Name: testCatalogHubName, + Index: "default", + URL: testHubURL, + Name: testCatalogHubName, }) hubCatalogs.Store( "anotherHub", settings.HubCatalog{ - ID: "anotherHub", - URL: testHubURL, - Name: testCatalogHubName, + Index: "1", + URL: testHubURL, + Name: testCatalogHubName, }) tests := []struct { annotations map[string]string diff --git a/pkg/params/info/info.go b/pkg/params/info/info.go index cb3b7d367..729b439f2 100644 --- a/pkg/params/info/info.go +++ b/pkg/params/info/info.go @@ -43,7 +43,7 @@ func (i *Info) UpdatePacOpts(logger *zap.SugaredLogger, configData map[string]st i.pacMutex.Lock() defer i.pacMutex.Unlock() - if err := settings.SyncConfig(logger, &i.Pac.Settings, configData); err != nil { + if err := settings.SyncConfig(logger, &i.Pac.Settings, configData, settings.DefaultValidators()); err != nil { return nil, err } return &i.Pac.Settings, nil diff --git a/pkg/params/info/info_test.go b/pkg/params/info/info_test.go index 9e36ca98c..c6d25dfe9 100644 --- a/pkg/params/info/info_test.go +++ b/pkg/params/info/info_test.go @@ -16,6 +16,6 @@ func TestNewInfo(t *testing.T) { catalog, ok := value.(settings.HubCatalog) assert.Equal(t, true, ok) - assert.Equal(t, catalog.ID, "default") + assert.Equal(t, catalog.Index, "default") assert.Equal(t, catalog.Name, settings.HubCatalogNameDefaultValue) } diff --git a/pkg/params/settings/config.go b/pkg/params/settings/config.go index 1dc7ff3aa..b89201062 100644 --- a/pkg/params/settings/config.go +++ b/pkg/params/settings/config.go @@ -35,9 +35,9 @@ var ( ) type HubCatalog struct { - ID string - Name string - URL string + Index string + Name string + URL string } // if there is a change performed on the default value, @@ -80,33 +80,31 @@ func DefaultSettings() Settings { newSettings := &Settings{} hubCatalog := &sync.Map{} hubCatalog.Store("default", HubCatalog{ - ID: "default", - Name: HubCatalogNameDefaultValue, - URL: HubURLDefaultValue, + Index: "default", + Name: HubCatalogNameDefaultValue, + URL: HubURLDefaultValue, }) newSettings.HubCatalogs = hubCatalog - _ = configutil.ValidateAndAssignValues(nil, map[string]string{}, newSettings, map[string]func(string) error{ - "ErrorDetectionSimpleRegexp": isValidRegex, - "TektonDashboardURL": isValidURL, - "CustomConsoleURL": isValidURL, - "CustomConsolePRTaskLog": startWithHTTPorHTTPS, - "CustomConsolePRDetail": startWithHTTPorHTTPS, - }, false) + _ = configutil.ValidateAndAssignValues(nil, map[string]string{}, newSettings, map[string]func(string) error{}, false) return *newSettings } -func SyncConfig(logger *zap.SugaredLogger, setting *Settings, config map[string]string) error { - setting.HubCatalogs = getHubCatalogs(logger, setting.HubCatalogs, config) - - err := configutil.ValidateAndAssignValues(logger, config, setting, map[string]func(string) error{ +func DefaultValidators() map[string]func(string) error { + return map[string]func(string) error{ "ErrorDetectionSimpleRegexp": isValidRegex, "TektonDashboardURL": isValidURL, "CustomConsoleURL": isValidURL, "CustomConsolePRTaskLog": startWithHTTPorHTTPS, "CustomConsolePRDetail": startWithHTTPorHTTPS, - }, true) + } +} + +func SyncConfig(logger *zap.SugaredLogger, setting *Settings, config map[string]string, validators map[string]func(string) error) error { + setting.HubCatalogs = getHubCatalogs(logger, setting.HubCatalogs, config) + + err := configutil.ValidateAndAssignValues(logger, config, setting, validators, true) if err != nil { return fmt.Errorf("failed to validate and assign values: %w", err) } diff --git a/pkg/params/settings/config_test.go b/pkg/params/settings/config_test.go index 30ab4ea82..39db26690 100644 --- a/pkg/params/settings/config_test.go +++ b/pkg/params/settings/config_test.go @@ -139,7 +139,7 @@ func TestSyncConfig(t *testing.T) { t.Run(tc.name, func(t *testing.T) { var test Settings - err := SyncConfig(logger, &test, tc.configMap) + err := SyncConfig(logger, &test, tc.configMap, DefaultValidators()) // set hub catalogs to nil to avoid comparison error // test separately @@ -166,5 +166,5 @@ func TestDefaultSettings(t *testing.T) { assert.Assert(t, ok) catalog, ok := catalogValue.(HubCatalog) assert.Assert(t, ok) - assert.Equal(t, catalog.ID, "default") + assert.Equal(t, catalog.Index, "default") } diff --git a/pkg/params/settings/convert.go b/pkg/params/settings/convert.go new file mode 100644 index 000000000..a0dc998b2 --- /dev/null +++ b/pkg/params/settings/convert.go @@ -0,0 +1,65 @@ +package settings + +import ( + "fmt" + "reflect" + "strconv" + "strings" + "sync" +) + +func ConvertPacStructToConfigMap(settings *Settings) map[string]string { + config := map[string]string{} + if settings == nil { + return config + } + structValue := reflect.ValueOf(settings).Elem() + structType := reflect.TypeOf(settings).Elem() + + for i := 0; i < structType.NumField(); i++ { + field := structType.Field(i) + fieldName := field.Name + + jsonTag := field.Tag.Get("json") + if jsonTag == "-" { + continue + } + key := strings.ToLower(jsonTag) + element := structValue.FieldByName(fieldName) + if !element.IsValid() { + continue + } + + //nolint + switch field.Type.Kind() { + case reflect.String: + config[key] = element.String() + case reflect.Bool: + config[key] = strconv.FormatBool(element.Bool()) + case reflect.Int: + config[key] = strconv.FormatInt(element.Int(), 10) + case reflect.Ptr: + // for hub catalogs map + if key == "" { + data := element.Interface().(*sync.Map) + data.Range(func(key, value interface{}) bool { + catalogData := value.(HubCatalog) + if key == "default" { + config[HubURLKey] = catalogData.URL + config[HubCatalogNameKey] = catalogData.Name + return true + } + config[fmt.Sprintf("%s-%s-%s", "catalog", catalogData.Index, "id")] = key.(string) + config[fmt.Sprintf("%s-%s-%s", "catalog", catalogData.Index, "name")] = catalogData.Name + config[fmt.Sprintf("%s-%s-%s", "catalog", catalogData.Index, "url")] = catalogData.URL + return true + }) + } + default: + // Skip unsupported field types + continue + } + } + + return config +} diff --git a/pkg/params/settings/convert_test.go b/pkg/params/settings/convert_test.go new file mode 100644 index 000000000..694914170 --- /dev/null +++ b/pkg/params/settings/convert_test.go @@ -0,0 +1,192 @@ +package settings + +import ( + "testing" + + "go.uber.org/zap" + zapobserver "go.uber.org/zap/zaptest/observer" + "gotest.tools/v3/assert" +) + +func TestConvert(t *testing.T) { + tests := []struct { + name string + inputConfig map[string]string + expectedConfig map[string]string + }{ + { + name: "empty configmap", + inputConfig: map[string]string{}, + expectedConfig: map[string]string{ + "application-name": "Pipelines as Code CI", + "auto-configure-new-github-repo": "false", + "auto-configure-repo-namespace-template": "", + "bitbucket-cloud-additional-source-ip": "", + "bitbucket-cloud-check-source-ip": "true", + "custom-console-name": "", + "custom-console-url": "", + "custom-console-url-namespace": "", + "custom-console-url-pr-details": "", + "custom-console-url-pr-tasklog": "", + "default-max-keep-runs": "0", + "error-detection-from-container-logs": "true", + "error-detection-max-number-of-lines": "50", + "error-detection-simple-regexp": "^(?P[^:]*):(?P[0-9]+):(?P[0-9]+)?([ ]*)?(?P.*)", + "error-log-snippet": "true", + "hub-catalog-name": "tekton", + "hub-url": "https://api.hub.tekton.dev/v1", + "max-keep-run-upper-limit": "0", + "remember-ok-to-test": "true", + "remote-tasks": "true", + "secret-auto-create": "true", + "secret-github-app-scope-extra-repos": "", + "secret-github-app-token-scoped": "true", + "tekton-dashboard-url": "", + }, + }, + { + name: "with few fields", + inputConfig: map[string]string{ + "application-name": "Pipelines as Code CI test name", + "auto-configure-new-github-repo": "false", + "auto-configure-repo-namespace-template": "", + "bitbucket-cloud-additional-source-ip": "", + "error-detection-from-container-logs": "true", + "error-detection-max-number-of-lines": "100", + "remote-tasks": "", + }, + expectedConfig: map[string]string{ + "application-name": "Pipelines as Code CI test name", + "auto-configure-new-github-repo": "false", + "auto-configure-repo-namespace-template": "", + "bitbucket-cloud-additional-source-ip": "", + "bitbucket-cloud-check-source-ip": "true", + "custom-console-name": "", + "custom-console-url": "", + "custom-console-url-namespace": "", + "custom-console-url-pr-details": "", + "custom-console-url-pr-tasklog": "", + "default-max-keep-runs": "0", + "error-detection-from-container-logs": "true", + "error-detection-max-number-of-lines": "100", + "error-detection-simple-regexp": "^(?P[^:]*):(?P[0-9]+):(?P[0-9]+)?([ ]*)?(?P.*)", + "error-log-snippet": "true", + "hub-catalog-name": "tekton", + "hub-url": "https://api.hub.tekton.dev/v1", + "max-keep-run-upper-limit": "0", + "remember-ok-to-test": "true", + "remote-tasks": "true", + "secret-auto-create": "true", + "secret-github-app-scope-extra-repos": "", + "secret-github-app-token-scoped": "true", + "tekton-dashboard-url": "", + }, + }, + { + name: "with few fields and default catalog", + inputConfig: map[string]string{ + "application-name": "Pipelines as Code CI test name", + "auto-configure-new-github-repo": "false", + "auto-configure-repo-namespace-template": "", + "bitbucket-cloud-additional-source-ip": "", + "error-detection-from-container-logs": "true", + "error-detection-max-number-of-lines": "100", + "hub-catalog-name": "test tekton", + "hub-url": "https://api.hub.tekton.dev/v2", + }, + expectedConfig: map[string]string{ + "application-name": "Pipelines as Code CI test name", + "auto-configure-new-github-repo": "false", + "auto-configure-repo-namespace-template": "", + "bitbucket-cloud-additional-source-ip": "", + "bitbucket-cloud-check-source-ip": "true", + "custom-console-name": "", + "custom-console-url": "", + "custom-console-url-namespace": "", + "custom-console-url-pr-details": "", + "custom-console-url-pr-tasklog": "", + "default-max-keep-runs": "0", + "error-detection-from-container-logs": "true", + "error-detection-max-number-of-lines": "100", + "error-detection-simple-regexp": "^(?P[^:]*):(?P[0-9]+):(?P[0-9]+)?([ ]*)?(?P.*)", + "error-log-snippet": "true", + "hub-catalog-name": "test tekton", + "hub-url": "https://api.hub.tekton.dev/v2", + "max-keep-run-upper-limit": "0", + "remember-ok-to-test": "true", + "remote-tasks": "true", + "secret-auto-create": "true", + "secret-github-app-scope-extra-repos": "", + "secret-github-app-token-scoped": "true", + "tekton-dashboard-url": "", + }, + }, + { + name: "with few fields and multi catalogs", + inputConfig: map[string]string{ + "application-name": "Pipelines as Code CI test name", + "auto-configure-new-github-repo": "false", + "auto-configure-repo-namespace-template": "", + "bitbucket-cloud-additional-source-ip": "", + "catalog-1-id": "anotherhub", + "catalog-1-name": "tekton", + "catalog-1-url": "https://api.other.com/v1", + "catalog-5-id": "anotherhub5", + "catalog-5-name": "tekton1", + "catalog-5-url": "https://api.other.com/v2", + "error-detection-from-container-logs": "true", + "error-detection-max-number-of-lines": "100", + "hub-catalog-name": "test tekton", + "hub-url": "https://api.hub.tekton.dev/v2", + }, + expectedConfig: map[string]string{ + "application-name": "Pipelines as Code CI test name", + "auto-configure-new-github-repo": "false", + "auto-configure-repo-namespace-template": "", + "bitbucket-cloud-additional-source-ip": "", + "bitbucket-cloud-check-source-ip": "true", + "catalog-1-id": "anotherhub", + "catalog-1-name": "tekton", + "catalog-1-url": "https://api.other.com/v1", + "catalog-5-id": "anotherhub5", + "catalog-5-name": "tekton1", + "catalog-5-url": "https://api.other.com/v2", + "custom-console-name": "", + "custom-console-url": "", + "custom-console-url-namespace": "", + "custom-console-url-pr-details": "", + "custom-console-url-pr-tasklog": "", + "default-max-keep-runs": "0", + "error-detection-from-container-logs": "true", + "error-detection-max-number-of-lines": "100", + "error-detection-simple-regexp": "^(?P[^:]*):(?P[0-9]+):(?P[0-9]+)?([ ]*)?(?P.*)", + "error-log-snippet": "true", + "hub-catalog-name": "test tekton", + "hub-url": "https://api.hub.tekton.dev/v2", + "max-keep-run-upper-limit": "0", + "remember-ok-to-test": "true", + "remote-tasks": "true", + "secret-auto-create": "true", + "secret-github-app-scope-extra-repos": "", + "secret-github-app-token-scoped": "true", + "tekton-dashboard-url": "", + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + observer, _ := zapobserver.New(zap.InfoLevel) + fakelogger := zap.New(observer).Sugar() + if tt.inputConfig == nil { + tt.inputConfig = map[string]string{} + } + settings := &Settings{} + err := SyncConfig(fakelogger, settings, tt.inputConfig, map[string]func(string) error{}) + if err != nil { + t.Errorf("not expecting error but got %s", err) + } + actualConfigData := ConvertPacStructToConfigMap(settings) + assert.DeepEqual(t, actualConfigData, tt.expectedConfig) + }) + } +} diff --git a/pkg/params/settings/default.go b/pkg/params/settings/default.go index 6537abf83..992b19117 100644 --- a/pkg/params/settings/default.go +++ b/pkg/params/settings/default.go @@ -21,26 +21,26 @@ func getHubCatalogs(logger *zap.SugaredLogger, catalogs *sync.Map, config map[st config[HubCatalogNameKey] = HubCatalogNameDefaultValue } catalogs.Store("default", HubCatalog{ - ID: "default", - Name: config[HubCatalogNameKey], - URL: config[HubURLKey], + Index: "default", + Name: config[HubCatalogNameKey], + URL: config[HubURLKey], }) for k := range config { m := hubCatalogNameRegex.FindStringSubmatch(k) if len(m) > 0 { - id := m[1] - cPrefix := fmt.Sprintf("catalog-%s", id) + index := m[1] + cPrefix := fmt.Sprintf("catalog-%s", index) skip := false for _, kk := range []string{"id", "name", "url"} { cKey := fmt.Sprintf("%s-%s", cPrefix, kk) // check if key exist in config if _, ok := config[cKey]; !ok { - logger.Warnf("CONFIG: hub %v should have the key %s, skipping catalog configuration", id, cKey) + logger.Warnf("CONFIG: hub %v should have the key %s, skipping catalog configuration", index, cKey) skip = true break } else if config[cKey] == "" { - logger.Warnf("CONFIG: hub %v catalog configuration is empty, skipping catalog configuration", id) + logger.Warnf("CONFIG: hub %v catalog configuration have empty value for key %s, skipping catalog configuration", index, cKey) skip = true break } @@ -61,15 +61,15 @@ func getHubCatalogs(logger *zap.SugaredLogger, catalogs *sync.Map, config map[st value, ok := catalogs.Load(catalogID) if ok { catalogValues, ok := value.(HubCatalog) - if ok && (catalogValues.Name == catalogName) && (catalogValues.URL == catalogURL) { - break + if ok && (catalogValues.Name == catalogName) && (catalogValues.URL == catalogURL) && (catalogValues.Index == index) { + continue } } logger.Infof("CONFIG: setting custom hub %s, catalog %s", catalogID, catalogURL) catalogs.Store(catalogID, HubCatalog{ - ID: catalogID, - Name: catalogName, - URL: catalogURL, + Index: index, + Name: catalogName, + URL: catalogURL, }) } } diff --git a/pkg/params/settings/default_test.go b/pkg/params/settings/default_test.go index 6e040bebe..5b9c0ae38 100644 --- a/pkg/params/settings/default_test.go +++ b/pkg/params/settings/default_test.go @@ -7,14 +7,15 @@ import ( "go.uber.org/zap" zapobserver "go.uber.org/zap/zaptest/observer" "gotest.tools/v3/assert" + "gotest.tools/v3/assert/cmp" ) func TestGetCatalogHub(t *testing.T) { hubCatalog := sync.Map{} hubCatalog.Store("custom", HubCatalog{ - ID: "custom", - URL: "https://foo.com", - Name: "tekton", + Index: "1", + URL: "https://foo.com", + Name: "tekton", }) tests := []struct { name string @@ -82,6 +83,17 @@ func TestGetCatalogHub(t *testing.T) { hubCatalogs: &sync.Map{}, wantLog: "CONFIG: hub 1 should have the key catalog-1-url, skipping catalog configuration", }, + { + name: "bad/missing value for custom catalog", + config: map[string]string{ + "catalog-1-id": "custom", + "catalog-1-name": "tekton", + "catalog-1-url": "", + }, + numCatalogs: 1, + hubCatalogs: &sync.Map{}, + wantLog: "CONFIG: hub 1 catalog configuration have empty value for key catalog-1-url, skipping catalog configuration", + }, { name: "bad/custom catalog called https", config: map[string]string{ @@ -122,6 +134,7 @@ func TestGetCatalogHub(t *testing.T) { if tt.wantLog != "" { assert.Assert(t, len(catcher.FilterMessageSnippet(tt.wantLog).TakeAll()) > 0, "could not find log message: got ", catcher) } + cmp.Equal(catalogs, tt.hubCatalogs) }) } } diff --git a/pkg/pipelineascode/pipelineascode_test.go b/pkg/pipelineascode/pipelineascode_test.go index f54b30c16..8b1fc164e 100644 --- a/pkg/pipelineascode/pipelineascode_test.go +++ b/pkg/pipelineascode/pipelineascode_test.go @@ -104,15 +104,15 @@ func TestRun(t *testing.T) { var hubCatalogs sync.Map hubCatalogs.Store( "default", settings.HubCatalog{ - ID: "default", - URL: testHubURL, - Name: testCatalogHubName, + Index: "default", + URL: testHubURL, + Name: testCatalogHubName, }) hubCatalogs.Store( "anotherHub", settings.HubCatalog{ - ID: "anotherHub", - URL: testHubURL, - Name: testCatalogHubName, + Index: "1", + URL: testHubURL, + Name: testCatalogHubName, }) observer, log := zapobserver.New(zap.InfoLevel) logger := zap.New(observer).Sugar() diff --git a/test/testdata/pipelinerun_remote_task_annotations.yaml b/test/testdata/pipelinerun_remote_task_annotations.yaml index 3755b02cf..7bdbe125e 100644 --- a/test/testdata/pipelinerun_remote_task_annotations.yaml +++ b/test/testdata/pipelinerun_remote_task_annotations.yaml @@ -9,8 +9,8 @@ metadata: pipelinesascode.tekton.dev/on-event: "[\\ .TargetEvent //]" pipelinesascode.tekton.dev/task: "[.other-tasks/task-referenced-internally.yaml]" pipelinesascode.tekton.dev/task-1: "[\\ .RemoteTaskURL //]" - pipelinesascode.tekton.dev/task-2: "pylint" - pipelinesascode.tekton.dev/task-3: "custom://curl" + pipelinesascode.tekton.dev/task-2: "custom://pylint" + pipelinesascode.tekton.dev/task-3: "custom2://curl" spec: pipelineRef: name: pipeline-in-tekton-dir