github.com/jcmturner/gokrb5/v8@v8.4.4/types/HostAddress_test.go (about) 1 package types 2 3 import ( 4 "encoding/hex" 5 "testing" 6 7 "github.com/jcmturner/gokrb5/v8/iana/addrtype" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestGetHostAddress(t *testing.T) { 12 tests := []struct { 13 str string 14 ipType int32 15 hex string 16 }{ 17 {"192.168.1.100", addrtype.IPv4, "c0a80164"}, 18 {"127.0.0.1", addrtype.IPv4, "7f000001"}, 19 {"[fe80::1cf3:b43b:df29:d43e]", addrtype.IPv6, "fe800000000000001cf3b43bdf29d43e"}, 20 } 21 for _, test := range tests { 22 h, err := GetHostAddress(test.str + ":1234") 23 if err != nil { 24 t.Errorf("error getting host for %s: %v", test.str, err) 25 } 26 assert.Equal(t, test.ipType, h.AddrType, "wrong address type for %s", test.str) 27 assert.Equal(t, test.hex, hex.EncodeToString(h.Address), "wrong address bytes for %s", test.str) 28 } 29 }