MCPcopy Create free account
hub / github.com/facebook/time / TestFormatHost

Function TestFormatHost

calnex/api/api_test.go:914–949  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

912 f, err := calnexAPI.FetchSystemMonitor()
913 require.NoError(t, err)
914 require.Equal(t, expected, f)
915}
916
917func TestFormatHost(t *testing.T) {
918 tests := []struct {
919 name string
920 input string
921 want string
922 wantErr bool
923 }{
924 {name: "IPv6 full", input: "2401:db00:2715:f002:face:0000:021a:0000", want: "[2401:db00:2715:f002:face:0000:021a:0000]"},
925 {name: "IPv6 loopback short", input: "::1", want: "[::1]"},
926 {name: "IPv6 already bracketed", input: "[2401:db00:2715:f002:face:0000:021a:0000]", want: "[2401:db00:2715:f002:face:0000:021a:0000]"},
927 {name: "IPv4 plain", input: "10.128.64.5", want: "10.128.64.5"},
928 {name: "FQDN", input: "calnex01.dc1.facebook.com", want: "calnex01.dc1.facebook.com"},
929 {name: "localhost", input: "localhost", want: "localhost"},
930
931 {name: "empty", input: "", wantErr: true},
932 {name: "spaces", input: "not valid", wantErr: true},
933 {name: "garbage in brackets", input: "[garbage]", wantErr: true},
934 {name: "IPv4 in brackets", input: "[10.128.64.5]", wantErr: true},
935 {name: "path injection", input: "host/extra", wantErr: true},
936 {name: "userinfo injection", input: "user@host", wantErr: true},
937 {name: "query injection", input: "host?x=1", wantErr: true},
938 {name: "fragment injection", input: "host#frag", wantErr: true},
939 }
940
941 for _, tt := range tests {
942 t.Run(tt.name, func(t *testing.T) {
943 got, err := formatHost(tt.input)
944 if tt.wantErr {
945 require.Error(t, err)
946 return
947 }
948 require.NoError(t, err)
949 require.Equal(t, tt.want, got)
950 })
951 }
952}

Callers

nothing calls this directly

Calls 3

formatHostFunction · 0.85
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…