github.com/opencontainers/runtime-tools@v0.9.0/validation/hostname/hostname.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"runtime"
     6  
     7  	"github.com/mndrix/tap-go"
     8  	"github.com/opencontainers/runtime-tools/validation/util"
     9  )
    10  
    11  func testHostname(t *tap.T, hostname string) error {
    12  	g, err := util.GetDefaultGenerator()
    13  	if err != nil {
    14  		return err
    15  	}
    16  
    17  	g.SetHostname(hostname)
    18  	g.AddAnnotation("TestName", fmt.Sprintf("check hostname %q", hostname))
    19  	err = util.RuntimeInsideValidate(g, t, nil)
    20  	t.Ok(err == nil, "hostname is set correctly")
    21  	if err != nil {
    22  		t.Diagnosticf("expect: err == nil, actual: err != nil")
    23  	}
    24  
    25  	return nil
    26  }
    27  
    28  func main() {
    29  	t := tap.New()
    30  	t.Header(0)
    31  	defer t.AutoPlan()
    32  
    33  	if "linux" != runtime.GOOS {
    34  		t.Skip(1, fmt.Sprintf("linux-specific namespace test"))
    35  	}
    36  
    37  	hostnames := []string{
    38  		"",
    39  		"hostname-specific",
    40  	}
    41  
    42  	for _, h := range hostnames {
    43  		if err := testHostname(t, h); err != nil {
    44  			t.Fail(err.Error())
    45  		}
    46  	}
    47  }