Skip to content

Commit fdcd30f

Browse files
authored
Merge pull request #640 from kinvolk/dongsu/test-empty-hostname
validation: test validation test with an empty hostname
2 parents d9a8ce7 + 582a909 commit fdcd30f

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

validation/hostname.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,46 @@
11
package main
22

33
import (
4+
"fmt"
5+
"runtime"
6+
7+
"github.com/mndrix/tap-go"
48
"github.com/opencontainers/runtime-tools/validation/util"
59
)
610

7-
func main() {
11+
func testHostname(t *tap.T, hostname string) error {
812
g, err := util.GetDefaultGenerator()
913
if err != nil {
10-
util.Fatal(err)
14+
return err
1115
}
12-
g.SetHostname("hostname-specific")
16+
17+
g.SetHostname(hostname)
1318
err = util.RuntimeInsideValidate(g, nil)
19+
t.Ok(err == nil, "hostname is set correctly")
1420
if err != nil {
15-
util.Fatal(err)
21+
t.Diagnosticf("expect: err == nil, actual: err != nil")
22+
}
23+
24+
return nil
25+
}
26+
27+
func main() {
28+
t := tap.New()
29+
t.Header(0)
30+
defer t.AutoPlan()
31+
32+
if "linux" != runtime.GOOS {
33+
t.Skip(1, fmt.Sprintf("linux-specific namespace test"))
34+
}
35+
36+
hostnames := []string{
37+
"",
38+
"hostname-specific",
39+
}
40+
41+
for _, h := range hostnames {
42+
if err := testHostname(t, h); err != nil {
43+
util.Fatal(err)
44+
}
1645
}
1746
}

0 commit comments

Comments
 (0)