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

Adding ControllerName struct, and test cases #84

Merged
merged 28 commits into from
Aug 24, 2023
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
740b217
add regex and unit test for checking if the given controller name is …
Aug 14, 2023
88173e1
added detail to comment
Aug 14, 2023
b92c97e
updating regex
Aug 15, 2023
cc185cc
moved to test idr
Aug 15, 2023
df92839
fixing import chnage
Aug 15, 2023
2842e2b
Merge branch 'main' into main
marcus-chris-hines Aug 15, 2023
59a919e
moving test case
Aug 15, 2023
e22bbc0
Merge branch 'main' of https://github.com/Marcus-Hines/aks-app-routin…
Aug 15, 2023
ce3312a
add controller utils
Aug 21, 2023
b90a767
fix trim on spaces
Aug 22, 2023
4feb03b
add test case for MetricsName
Aug 22, 2023
6ee11c7
testing logger name also
Aug 22, 2023
0ed635f
Merge branch 'main' into main
marcus-chris-hines Aug 22, 2023
f39b76e
fixing bug in clean
Aug 22, 2023
71d25fe
Merge branch 'main' of https://github.com/Marcus-Hines/aks-app-routin…
Aug 22, 2023
ae35c2c
moved the test utils test to controller utisl
Aug 22, 2023
7612113
using a New function instead of clean
Aug 22, 2023
b5b3e31
updated tests to use New
Aug 22, 2023
2342361
fixing value of test case string
Aug 22, 2023
997b29b
update comment on conrollerName struc
Aug 22, 2023
ac6dffc
fix typo in test cases
Aug 23, 2023
b45da93
adding test cases for spaces
Aug 23, 2023
b7cc8b0
removing test that no longer has value
Aug 23, 2023
9520695
updated removespace to instead only allow letters
Aug 23, 2023
c4fa8c3
testing strip
Aug 23, 2023
38a9dd3
fixing strip method
Aug 23, 2023
83bd476
fixing stripped funciton
Aug 23, 2023
0e5659b
specialchars test
Aug 23, 2023
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
Prev Previous commit
Next Next commit
using a New function instead of clean
  • Loading branch information
Marcus Hines committed Aug 22, 2023
commit 76121137846be852a5d9df34d77d446cff43a53f
29 changes: 20 additions & 9 deletions pkg/controller/controller_utils/controller_utils.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package controller_utils
Marcus-Hines marked this conversation as resolved.
Show resolved Hide resolved

import (
"regexp"
"strings"
"unicode"
)

const (
@@ -17,13 +17,24 @@ type ControllerNamer interface {

type ControllerName []string
Marcus-Hines marked this conversation as resolved.
Show resolved Hide resolved

func (c ControllerName) clean(delimiter string) ControllerName {
for i := range c {
// replace spaces with _
space := regexp.MustCompile(`\s+`)
c[i] = space.ReplaceAllString(strings.TrimSpace(c[i]), delimiter)
func NewControllerName(controllerName []string) ControllerName {
Marcus-Hines marked this conversation as resolved.
Show resolved Hide resolved
cn := make(ControllerName, len(controllerName))

for i, w := range controllerName {
cn[i] = removeSpace(strings.ToLower(w))

}
return c
return cn
}

func removeSpace(s string) string {
rr := make([]rune, 0, len(s))
for _, r := range s {
if !unicode.IsSpace(r) {
rr = append(rr, r)
}
}
return string(rr)
}

func (c ControllerName) lowercase() ControllerName {
Marcus-Hines marked this conversation as resolved.
Show resolved Hide resolved
@@ -34,9 +45,9 @@ func (c ControllerName) lowercase() ControllerName {
}

func (c ControllerName) MetricsName() string {
return strings.Join(c.lowercase().clean(metricsNameDelimiter), metricsNameDelimiter)
return strings.Join(c, metricsNameDelimiter)
}

func (c ControllerName) LoggerName() string {
return strings.Join(c.lowercase().clean(loggerNameDelimiter), loggerNameDelimiter)
return strings.Join(c, loggerNameDelimiter)
}