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

test: add unit-test for PR 1743 v2 #1752

Merged
merged 2 commits into from
Nov 7, 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
5 changes: 2 additions & 3 deletions pkg/transformer/kubernetes/k8sutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,12 +857,11 @@ func FormatEnvName(name string) string {
if strings.Contains(envName, "/") {
envName = envName[strings.LastIndex(envName, "/")+1:]
}
// take only last 63 chars
// take only last chars: The ones after 63th index
if len(envName) > 63 {
envName = envName[len(envName)-63:]
}
envName = strings.Replace(envName, ".", "-", -1)
return envName
return strings.Replace(envName, ".", "-", -1)
}

// FormatFileName format file name
Expand Down
47 changes: 47 additions & 0 deletions pkg/transformer/kubernetes/k8sutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,3 +657,50 @@ func TestReadOnlyRootFS(t *testing.T) {
}
}
}

func TestFormatEnvName(t *testing.T) {
type args struct {
name string
}
tests := []struct {
name string
args args
want string
}{
{
name: "check dot conversion",
args: args{
name: "random.test",
},
want: "random-test",
},
{
name: "check that path is shortened",
args: args{
name: "random/test/v1",
},
want: "v1",
},
{
name: "check that ./ is removed",
args: args{
name: "./random",
},
want: "random",
},
{
name: "check that ./ is removed",
args: args{
name: "abcdefghijklnmopqrstuvxyzabcdefghijklmnopqrstuvwxyzabcdejghijkl$Hereisadditional",
},
want: "rstuvxyzabcdefghijklmnopqrstuvwxyzabcdejghijkl$Hereisadditional",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := FormatEnvName(tt.args.name); got != tt.want {
t.Errorf("FormatEnvName() = %v, want %v", got, tt.want)
}
})
}
}