bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/host/name_test.go (about) 1 package host 2 3 import "testing" 4 5 func TestFormatName_Short(t *testing.T) { 6 testCases := make([][]string, 3) 7 testCases[0] = []string{"freddy", "freddy"} 8 testCases[1] = []string{"freddy.somewhere.com", "freddy"} 9 testCases[2] = []string{"192.168.17.6", "192.168.17.6"} 10 11 np, err := NewHostNameProcessor(false) 12 if err != nil { 13 t.Error(err) 14 return 15 } 16 17 for i, tc := range testCases { 18 name, err := np.FormatName(tc[0]) 19 if err != nil { 20 t.Error(err) 21 } 22 23 if name != tc[1] { 24 t.Errorf("Iteration %d: '%s' != '%s'", i, tc[1], name) 25 } 26 } 27 } 28 29 func TestFormatName_Full(t *testing.T) { 30 testCases := make([]string, 3) 31 testCases[0] = "freddy" 32 testCases[1] = "freddy.somewhere.com" 33 testCases[2] = "192.168.17.6" 34 35 np, err := NewHostNameProcessor(true) 36 if err != nil { 37 t.Error(err) 38 return 39 } 40 41 for i, tc := range testCases { 42 name, err := np.FormatName(tc) 43 if err != nil { 44 t.Error(err) 45 } 46 47 if name != tc { 48 t.Errorf("Iteration %d: '%s' != '%s'", i, tc, name) 49 } 50 } 51 }