Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop some unused functions #152

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 0 additions & 48 deletions controllers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
39 changes: 0 additions & 39 deletions controllers/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -52,37 +44,6 @@ var testCases = []struct {
{"[email protected]: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 {
Expand Down
Loading