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

Fix CleanResourceName for IDs starting with a - characted #1945

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ provider_installation {
Acceptance tests require a running instance of Grafana. You can either handle
running an instance of Grafana yourself or use `docker-compose`.

If you choose `docker-compose`, run `make testacc-docker`. This is the simplest
If you choose `docker-compose`, run `make testacc-oss-docker`. This is the simplest
option, but often not the quickest.

Alternatively you can use the `testacc` target which will use your local `go`
Expand Down
3 changes: 3 additions & 0 deletions pkg/generate/postprocessing/preferred_resource_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,8 @@ func CleanResourceName(name string) string {
if cleaned[0] >= '0' && cleaned[0] <= '9' {
cleaned = "_" + cleaned
}
if cleaned[0] == '-' {
cleaned = "_" + cleaned
}
return cleaned
}
26 changes: 25 additions & 1 deletion pkg/generate/postprocessing/preferred_resource_name_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package postprocessing

import "testing"
import (
"fmt"
"testing"
)

func TestUsePreferredResourceNames(t *testing.T) {
for _, testFile := range []string{
Expand All @@ -11,3 +14,24 @@ func TestUsePreferredResourceNames(t *testing.T) {
})
}
}

func TestCleanResourceName(t *testing.T) {
var tests = []struct {
before, after string
}{
{"qwerty", "qwerty"},
{"123", "_123"},
{"-foo", "_-foo"},
{"_bar", "_bar"},
}

for _, tt := range tests {
testname := fmt.Sprintf("%s,%s", tt.before, tt.after)
t.Run(testname, func(t *testing.T) {
cleaned := CleanResourceName(tt.before)
if cleaned != tt.after {
t.Errorf(`Resource name %q was clean as %q and not %q as expected`, tt.before, cleaned, tt.after)
}
})
}
}
Loading