Skip to content

Commit

Permalink
Fixes tests, case sensitive now
Browse files Browse the repository at this point in the history
  • Loading branch information
foot committed Mar 20, 2023
1 parent f59c3a1 commit 9b45d66
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
15 changes: 6 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func main() {
setupLog.Error(err, "invalid enabled generators")
os.Exit(1)
}
setupLog.Info("Enabled generators", "generators", enabledGenerators)

initScheme(enabledGenerators)

Expand Down Expand Up @@ -129,8 +130,6 @@ func main() {
}
metricsH := runtimeCtrl.MustMakeMetrics(mgr)

setupLog.Info("Enabled generators", "generators", enabledGenerators)

if err = (&controllers.GitOpsSetReconciler{
Client: mgr.GetClient(),
DefaultServiceAccount: defaultServiceAccount,
Expand Down Expand Up @@ -171,26 +170,24 @@ func validateEnabledGenerators(enabledGenerators []string) error {
}

func getGenerators(enabledGenerators []string) map[string]generators.GeneratorFactory {
matrixGenerators := map[string]generators.GeneratorFactory{
matrixGenerators := filterEnabledGenerators(enabledGenerators, map[string]generators.GeneratorFactory{
"List": list.GeneratorFactory,
"GitRepository": gitrepository.GeneratorFactory,
"PullRequests": pullrequests.GeneratorFactory,
"Cluster": cluster.GeneratorFactory,
// TODO: Figure out how to configure the client
"APIClient": apiclient.GeneratorFactory(http.DefaultClient),
}
})

allGenerators := map[string]generators.GeneratorFactory{
return filterEnabledGenerators(enabledGenerators, map[string]generators.GeneratorFactory{
"List": list.GeneratorFactory,
"GitRepository": gitrepository.GeneratorFactory,
"PullRequests": pullrequests.GeneratorFactory,
"Cluster": cluster.GeneratorFactory,
// TODO: Figure out how to configure the client
"APIClient": apiclient.GeneratorFactory(http.DefaultClient),
"Matrix": matrix.GeneratorFactory(filterEnabledGenerators(enabledGenerators, matrixGenerators)),
}

return filterEnabledGenerators(enabledGenerators, allGenerators)
"Matrix": matrix.GeneratorFactory(matrixGenerators),
})
}

func filterEnabledGenerators(enabledGenerators []string, gens map[string]generators.GeneratorFactory) map[string]generators.GeneratorFactory {
Expand Down
14 changes: 12 additions & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@ func TestGetGenerators(t *testing.T) {
},
{
"enabled generators",
[]string{"cluster", "list"},
[]string{"Cluster", "List"},
[]string{"Cluster", "List"},
},
{
"case is important",
[]string{"cluster", "List"},
[]string{"List"},
},
{
"unknown enabled generators are ignored",
[]string{"cluster", "list", "foo"},
[]string{"Cluster", "List", "foo"},
[]string{"Cluster", "List"},
},
}
Expand Down Expand Up @@ -67,6 +72,11 @@ func TestValidateEnabledGenerators(t *testing.T) {
[]string{"Cluster", "List", "foo"},
`invalid generator "foo". valid values: \["GitRepository" "Cluster" "PullRequests" "List" "APIClient" "Matrix"\]`,
},
{
"case insensitive generarors",
[]string{"cluster", "List"},
`invalid generator "cluster". valid values: \["GitRepository" "Cluster" "PullRequests" "List" "APIClient" "Matrix"\]`,
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 9b45d66

Please sign in to comment.