Skip to content

Commit

Permalink
Merge linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
theunrepentantgeek committed Sep 1, 2024
2 parents a42427f + e1a23c8 commit cee2185
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 15 deletions.
62 changes: 54 additions & 8 deletions v2/internal/controllers/samples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,58 @@ func findRefsAndCreateSecrets(tc *testcommon.KubePerTestContext, resources []cli
}

func getTestName(group string, version string) string {
caser := cases.Title(language.English)
return strings.Join(
[]string{
"Test",
caser.String(group),
version,
"CreationAndDeletion",
}, "_")
var result strings.Builder

// Common Prefix
result.WriteString("Test_")

// Titlecase for each part of the group
title := cases.Title(language.English)
for _, part := range strings.Split(group, ".") {
result.WriteString(title.String(part))
}
result.WriteString("_")

// Append the version
result.WriteString(version)

// Common Suffix
result.WriteString("_CreationAndDeletion")

return result.String()
}

func TestGetTestName(t *testing.T) {
t.Parallel()

cases := map[string]struct {
group string
version string
expected string
}{
"simple": {
group: "group",
version: "version",
expected: "Test_Group_version_CreationAndDeletion",
},
"Network": {
group: "network",
version: "v1api",
expected: "Test_Network_v1api_CreationAndDeletion",
},
"Frontdoor": {
group: "network.frontdoor",
version: "v1api",
expected: "Test_NetworkFrontdoor_v1api_CreationAndDeletion",
},
}

for name, c := range cases {
c := c
t.Run(name, func(t *testing.T) {
t.Parallel()
g := NewGomegaWithT(t)
g.Expect(getTestName(c.group, c.version)).To(Equal(c.expected))
})
}
}
11 changes: 4 additions & 7 deletions v2/tools/generator/internal/astmodel/identifier_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"unicode"

"github.com/Azure/azure-service-operator/v2/internal/set"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

// \W is all non-word characters (https://golang.org/pkg/regexp/syntax/)
Expand Down Expand Up @@ -176,18 +178,13 @@ func (factory *identifierFactory) cleanPart(part string, visibility Visibility)
clean := filterRegex.ReplaceAllLiteralString(part, " ")
cleanWords := sliceIntoWords(clean)
caseCorrectedWords := make([]string, 0, len(cleanWords))
title := cases.Title(language.English, cases.NoLower)
for ix, word := range cleanWords {
var w string
if ix == 0 && visibility == NotExported {
w = strings.ToLower(word)
} else {
// Disable lint: the suggested "replacement" for this in /x/cases has fundamental
// differences in how it works (e.g. 'JSON' becomes 'Json'; we don’t want that).
// Furthermore, the cases (ha) that it "fixes" are not relevant to us
// (something about better handling of various punctuation characters;
// our words are punctuation-free).
//nolint:staticcheck
w = strings.Title(word)
w = title.String(word)
}

caseCorrectedWords = append(caseCorrectedWords, w)
Expand Down

0 comments on commit cee2185

Please sign in to comment.