forked from containers/buildah
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_common_test.go
31 lines (28 loc) · 1.39 KB
/
run_common_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package buildah
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestMapContainerNameToHostname(t *testing.T) {
cases := [][2]string{
{"trivial", "trivial"},
{"Nottrivial", "Nottrivial"},
{"0Nottrivial", "0Nottrivial"},
{"0Nottrivi-al", "0Nottrivi-al"},
{"-0Nottrivi-al", "0Nottrivi-al"},
{".-0Nottrivi-.al", "0Nottrivi-.al"},
{".-0Nottrivi-.al0123456789", "0Nottrivi-.al0123456789"},
{".-0Nottrivi-.al0123456789+0123456789", "0Nottrivi-.al01234567890123456789"},
{".-0Nottrivi-.al0123456789+0123456789/0123456789", "0Nottrivi-.al012345678901234567890123456789"},
{".-0Nottrivi-.al0123456789+0123456789/0123456789%0123456789", "0Nottrivi-.al0123456789012345678901234567890123456789"},
{".-0Nottrivi-.al0123456789+0123456789/0123456789%0123456789_0123456789", "0Nottrivi-.al01234567890123456789012345678901234567890123456789"},
{".-0Nottrivi-.al0123456789+0123456789/0123456789%0123456789_0123456789:0123456", "0Nottrivi-.al012345678901234567890123456789012345678901234567890"},
{".-0Nottrivi-.al0123456789+0123456789/0123456789%0123456789_0123456789:0123456789", "0Nottrivi-.al012345678901234567890123456789012345678901234567890"},
}
for i := range cases {
t.Run(cases[i][0], func(t *testing.T) {
sanitized := mapContainerNameToHostname(cases[i][0])
assert.Equalf(t, cases[i][1], sanitized, "mapping container name %q to a valid hostname", cases[i][0])
})
}
}