-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #606 from gdbranco/feat/ocm-6030
OCM-6030 | feat: allow to edit component routes of ingress
- Loading branch information
Showing
10 changed files
with
284 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package ingress | ||
|
||
import ( | ||
"fmt" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Parse component routes", func() { | ||
It("Parses input string for component routes", func() { | ||
componentRouteBuilder, err := parseComponentRoutes( | ||
//nolint:lll | ||
"oauth: hostname=oauth-host;tlsSecretRef=oauth-secret,downloads: hostname=downloads-host;tlsSecretRef=downloads-secret,console: hostname=console-host;tlsSecretRef=console-secret", | ||
) | ||
Expect(err).To(BeNil()) | ||
for key, builder := range componentRouteBuilder { | ||
expectedHostname := fmt.Sprintf("%s-host", key) | ||
expectedTlsRef := fmt.Sprintf("%s-secret", key) | ||
componentRoute, err := builder.Build() | ||
Expect(err).To(BeNil()) | ||
Expect(componentRoute.Hostname()).To(Equal(expectedHostname)) | ||
Expect(componentRoute.TlsSecretRef()).To(Equal(expectedTlsRef)) | ||
} | ||
}) | ||
Context("Fails to parse input string for component routes", func() { | ||
It("fails due to invalid component route", func() { | ||
_, err := parseComponentRoutes( | ||
//nolint:lll | ||
"unknown: hostname=oauth-host;tlsSecretRef=oauth-secret,downloads: hostname=downloads-host;tlsSecretRef=downloads-secret,console: hostname=console-host;tlsSecretRef=console-secret", | ||
) | ||
Expect(err).ToNot(BeNil()) | ||
Expect( | ||
err.Error(), | ||
).To(Equal("'unknown' is not a valid component name. Expected include [oauth, console, downloads]")) | ||
}) | ||
It("fails due to wrong amount of component routes", func() { | ||
_, err := parseComponentRoutes( | ||
//nolint:lll | ||
"oauth: hostname=oauth-host;tlsSecretRef=oauth-secret,downloads: hostname=downloads-host;tlsSecretRef=downloads-secret", | ||
) | ||
Expect(err).ToNot(BeNil()) | ||
Expect( | ||
err.Error(), | ||
).To(Equal("the expected amount of component routes is 3, but 2 have been supplied")) | ||
}) | ||
It("fails if it can split ':' in more than they key separation", func() { | ||
_, err := parseComponentRoutes( | ||
//nolint:lll | ||
"oauth: hostname=oauth:-host;tlsSecretRef=oauth-secret,downloads: hostname=downloads-host;tlsSecretRef=downloads-secret,", | ||
) | ||
Expect(err).ToNot(BeNil()) | ||
Expect( | ||
err.Error(), | ||
).To(Equal("only the name of the component should be followed by ':'")) | ||
}) | ||
It("fails due to invalid parameter", func() { | ||
_, err := parseComponentRoutes( | ||
//nolint:lll | ||
"oauth: unknown=oauth-host;tlsSecretRef=oauth-secret,downloads: hostname=downloads-host;tlsSecretRef=downloads-secret,console: hostname=console-host;tlsSecretRef=console-secret", | ||
) | ||
Expect(err).ToNot(BeNil()) | ||
Expect( | ||
err.Error(), | ||
).To(Equal("'unknown' is not a valid parameter for a component route. Expected include [hostname, tlsSecretRef]")) | ||
}) | ||
It("fails due to wrong amount of parameters", func() { | ||
_, err := parseComponentRoutes( | ||
//nolint:lll | ||
"oauth: hostname=oauth-host,downloads: hostname=downloads-host;tlsSecretRef=downloads-secret,console: hostname=console-host;tlsSecretRef=console-secret", | ||
) | ||
Expect(err).ToNot(BeNil()) | ||
Expect( | ||
err.Error(), | ||
).To(Equal("only 2 parameters are expected for each component")) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package ingress | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestEditCluster(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Edit ingress suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package utils | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestEditCluster(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Utils suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package utils | ||
|
||
import "reflect" | ||
|
||
func Contains[T comparable](slice []T, element T) bool { | ||
for _, sliceElement := range slice { | ||
if reflect.DeepEqual(sliceElement, element) { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package utils | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Slices", func() { | ||
Context("Validates Contains", func() { | ||
It("Return false when input is empty", func() { | ||
Expect(false).To(Equal(Contains([]string{}, "any"))) | ||
}) | ||
|
||
It("Return true when input is populated and present", func() { | ||
Expect(true).To(Equal(Contains([]string{"test", "any"}, "any"))) | ||
}) | ||
|
||
It("Return false when input is populated and not present", func() { | ||
Expect(false).To(Equal(Contains([]string{"test", "any"}, "none"))) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package utils | ||
|
||
import ( | ||
"sort" | ||
"strings" | ||
) | ||
|
||
func SliceToSortedString(s []string) string { | ||
if len(s) == 0 { | ||
return "" | ||
} | ||
SortStringRespectLength(s) | ||
return "[" + strings.Join(s, ", ") + "]" | ||
} | ||
|
||
func SortStringRespectLength(s []string) { | ||
sort.Slice(s, func(i, j int) bool { | ||
l1, l2 := len(s[i]), len(s[j]) | ||
if l1 != l2 { | ||
return l1 < l2 | ||
} | ||
return s[i] < s[j] | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package utils | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Validates SliceToSortedString", func() { | ||
It("Empty when slice is empty", func() { | ||
s := SliceToSortedString([]string{}) | ||
Expect("").To(Equal(s)) | ||
}) | ||
|
||
It("Sorted when slice is filled", func() { | ||
s := SliceToSortedString([]string{"b", "a", "c", "a10", "a1", "a20", "a2", "1", "2", "10", "20"}) | ||
Expect("[1, 2, a, b, c, 10, 20, a1, a2, a10, a20]").To(Equal(s)) | ||
}) | ||
}) |