diff --git a/controllers/utils.go b/controllers/utils.go index 6be6556da..b7e1550cd 100644 --- a/controllers/utils.go +++ b/controllers/utils.go @@ -44,54 +44,6 @@ func logOnce(message string) { log.Println(message) } -// ContainsString checks if the string array contains the given string. -func ContainsString(slice []string, s string) bool { - for _, item := range slice { - if item == s { - return true - } - } - return false -} - -// RemoveString removes the given string from the string array if exists. -func RemoveString(slice []string, s string) (result []string) { - for _, item := range slice { - if item == s { - continue - } - result = append(result, item) - } - return result -} - -func ParametersToMap(parameters []api.PatternParameter) map[string]any { - output := map[string]any{} - for _, p := range parameters { - keys := strings.Split(p.Name, ".") - max := len(keys) - 1 - current := output - - for i, key := range keys { - fmt.Printf("Step %d %s\n", i, key) - if i == max { - current[key] = p.Value - } else { - if val, ok := current[key]; ok { - fmt.Printf("Using %q\n", key) - current = val.(map[string]any) - } else if i < len(key) { - fmt.Printf("Adding %q\n", key) - current[key] = map[string]any{} - current = current[key].(map[string]any) - } - } - } - } - - return output -} - // getPatternConditionByStatus returns a copy of the pattern condition defined by the status and the index in the slice if it exists, otherwise -1 and nil func getPatternConditionByStatus(conditions []api.PatternCondition, conditionStatus v1.ConditionStatus) (int, *api.PatternCondition) { if conditions == nil { diff --git a/controllers/utils_test.go b/controllers/utils_test.go index 0345e7890..edee23de1 100644 --- a/controllers/utils_test.go +++ b/controllers/utils_test.go @@ -17,16 +17,8 @@ limitations under the License. package controllers import ( - "fmt" - . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - logf "sigs.k8s.io/controller-runtime/pkg/log" - "sigs.k8s.io/controller-runtime/pkg/log/zap" - - "github.com/ghodss/yaml" - - gitopsv1alpha1 "github.com/hybrid-cloud-patterns/patterns-operator/api/v1alpha1" //+kubebuilder:scaffold:imports ) @@ -52,37 +44,6 @@ var testCases = []struct { {"git@github.com:mbaldessari/common", "common", "github.com"}, } -// These tests use Ginkgo (BDD-style Go testing framework). Refer to -// http://onsi.github.io/ginkgo/ to learn more about Ginkgo. - -var _ = Describe("Parameter Unpacking", func() { - var parameters []gitopsv1alpha1.PatternParameter - - BeforeEach(func() { - logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) - logf.Log.Info("Running util test") - - parameters = []gitopsv1alpha1.PatternParameter{ - { - Name: "global.git.repo", - Value: "https://github.com/some/place", - }, - { - Name: "global.git.server", - Value: "github.com", - }, - } - }) - - It("should convert values", func() { - fmt.Printf("Converting values\n") - out := ParametersToMap(parameters) - out_s, err := yaml.Marshal(out) - Expect(err).NotTo(HaveOccurred()) - fmt.Printf("Converted values:\n%s\n", out_s) - }) -}) - var _ = Describe("ExtractRepositoryName", func() { It("should extract the repository name from various URL formats", func() { for _, testCase := range testCases {