github.com/cilium/cilium@v1.16.2/pkg/node/types/nodename_test.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package types 5 6 import ( 7 "os" 8 "testing" 9 10 "github.com/stretchr/testify/require" 11 ) 12 13 func TestHostname(t *testing.T) { 14 h, err := os.Hostname() 15 16 // Unmodified node-name value is either os.Hostname if available or 17 // "localhost" otherwise 18 if err != nil { 19 require.Equal(t, "localhost", GetName()) 20 } else { 21 require.Equal(t, h, GetName()) 22 } 23 24 newName := "foo.domain" 25 SetName(newName) 26 require.Equal(t, newName, GetName()) 27 }