Skip to content

Commit a2a110e

Browse files
Shivam Mukhadechmouel
authored andcommitted
Validate setting only if defined
if settings are not defined and we validate empty string it was failing for tektondashboard url, but anyway we should validate only if value is set. Signed-off-by: Shivam Mukhade <[email protected]>
1 parent 94d1024 commit a2a110e

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

pkg/params/settings/validation.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ import (
77
)
88

99
func Validate(config map[string]string) error {
10-
if secretAutoCreation, ok := config[SecretAutoCreateKey]; ok {
10+
if secretAutoCreation, ok := config[SecretAutoCreateKey]; ok && secretAutoCreation != "" {
1111
if !isValidBool(secretAutoCreation) {
1212
return fmt.Errorf("invalid value for key %v, acceptable values: true or false", SecretAutoCreateKey)
1313
}
1414
}
1515

16-
if remoteTask, ok := config[RemoteTasksKey]; ok {
16+
if remoteTask, ok := config[RemoteTasksKey]; ok && remoteTask != "" {
1717
if !isValidBool(remoteTask) {
1818
return fmt.Errorf("invalid value for key %v, acceptable values: true or false", RemoteTasksKey)
1919
}
2020
}
2121

22-
if check, ok := config[BitbucketCloudCheckSourceIPKey]; ok {
22+
if check, ok := config[BitbucketCloudCheckSourceIPKey]; ok && check != "" {
2323
if !isValidBool(check) {
2424
return fmt.Errorf("invalid value for key %v, acceptable values: true or false", BitbucketCloudCheckSourceIPKey)
2525
}
@@ -39,13 +39,13 @@ func Validate(config map[string]string) error {
3939
}
4040
}
4141

42-
if check, ok := config[AutoConfigureNewGitHubRepoKey]; ok {
42+
if check, ok := config[AutoConfigureNewGitHubRepoKey]; ok && check != "" {
4343
if !isValidBool(check) {
4444
return fmt.Errorf("invalid value for key %v, acceptable values: true or false", AutoConfigureNewGitHubRepoKey)
4545
}
4646
}
4747

48-
if dashboardURL, ok := config[TektonDashboardURLKey]; ok {
48+
if dashboardURL, ok := config[TektonDashboardURLKey]; ok && dashboardURL != "" {
4949
if _, err := url.ParseRequestURI(dashboardURL); err != nil {
5050
return fmt.Errorf("invalid value for key %v, invalid url: %w", TektonDashboardURLKey, err)
5151
}

pkg/params/settings/validation_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ func TestValidate(t *testing.T) {
5858
},
5959
wantErr: "invalid value for key tekton-dashboard-url, invalid url: parse \"abc.xyz\": invalid URI for request",
6060
},
61+
{
62+
name: "empty values",
63+
config: map[string]string{
64+
RemoteTasksKey: "",
65+
SecretAutoCreateKey: "",
66+
BitbucketCloudCheckSourceIPKey: "",
67+
TektonDashboardURLKey: "",
68+
MaxKeepRunUpperLimitKey: "",
69+
AutoConfigureNewGitHubRepoKey: "",
70+
DefaultMaxKeepRunsKey: "",
71+
},
72+
wantErr: "",
73+
},
6174
}
6275
for _, tt := range tests {
6376
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)