forked from LaconicNetwork/kompose
Merge pull request #1752 from AhmedGrati/1745-add-test-for-pr-1743
test: add unit-test for PR 1743 v2
This commit is contained in:
commit
900f0b0b5e
@ -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
|
||||
|
||||
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user