File: hostname.go

package info (click to toggle)
golang-github-opencontainers-runtime-tools 0.9.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,108 kB
  • sloc: sh: 557; makefile: 104
file content (47 lines) | stat: -rw-r--r-- 862 bytes parent folder | download | duplicates (2)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main

import (
	"fmt"
	"runtime"

	"github.com/mndrix/tap-go"
	"github.com/opencontainers/runtime-tools/validation/util"
)

func testHostname(t *tap.T, hostname string) error {
	g, err := util.GetDefaultGenerator()
	if err != nil {
		return err
	}

	g.SetHostname(hostname)
	g.AddAnnotation("TestName", fmt.Sprintf("check hostname %q", hostname))
	err = util.RuntimeInsideValidate(g, t, nil)
	t.Ok(err == nil, "hostname is set correctly")
	if err != nil {
		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 {
			t.Fail(err.Error())
		}
	}
}