From 582a909a278ce4029586240349272391adec7a83 Mon Sep 17 00:00:00 2001 From: Dongsu Park Date: Thu, 24 May 2018 10:42:41 +0200 Subject: [PATCH] validation: test validation test with an empty hostname Check if the hostname test works also with an empty hostname, i.e, `hostname == ""`. Also print out TAP results. Signed-off-by: Dongsu Park --- validation/hostname.go | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/validation/hostname.go b/validation/hostname.go index 1642b62d4..1cce37d8e 100644 --- a/validation/hostname.go +++ b/validation/hostname.go @@ -1,17 +1,46 @@ package main import ( + "fmt" + "runtime" + + "github.com/mndrix/tap-go" "github.com/opencontainers/runtime-tools/validation/util" ) -func main() { +func testHostname(t *tap.T, hostname string) error { g, err := util.GetDefaultGenerator() if err != nil { - util.Fatal(err) + return err } - g.SetHostname("hostname-specific") + + g.SetHostname(hostname) err = util.RuntimeInsideValidate(g, nil) + t.Ok(err == nil, "hostname is set correctly") if err != nil { - util.Fatal(err) + t.Diagnosticf("expect: err == nil, actual: err != nil") + } + + return nil +} + +func main() { + t := tap.New() + t.Header(0) + defer t.AutoPlan() + + if "linux" != runtime.GOOS { + t.Skip(1, fmt.Sprintf("linux-specific namespace test")) + } + + hostnames := []string{ + "", + "hostname-specific", + } + + for _, h := range hostnames { + if err := testHostname(t, h); err != nil { + util.Fatal(err) + } } }