github.com/zooyer/miskit@v1.0.71/sdk/ips/ip.hzz.cool_test.go (about) 1 package ips 2 3 import ( 4 "context" 5 "github.com/zooyer/miskit/log" 6 "github.com/zooyer/miskit/zrpc" 7 "reflect" 8 "testing" 9 "time" 10 ) 11 12 func TestClient_QueryIP(t *testing.T) { 13 type fields struct { 14 url string 15 option Option 16 client *zrpc.Client 17 } 18 type args struct { 19 ctx context.Context 20 ip string 21 } 22 var ( 23 config = log.Config{ 24 Level: "DEBUG", 25 } 26 stdout = log.NewStdoutRecorder(log.TextFormatter(true)) 27 logger, _ = log.New(config, nil) 28 ) 29 logger.SetDefaultRecorder(stdout) 30 tests := []struct { 31 name string 32 args args 33 want *IP 34 wantErr bool 35 }{ 36 { 37 name: "test", 38 args: args{ 39 ctx: context.Background(), 40 ip: "111.204.182.91", 41 }, 42 want: &IP{ 43 IP: "111.204.182.91", 44 Country: "中国", 45 Province: "北京", 46 City: "北京", 47 County: "", 48 Region: "亚洲", 49 ISP: "联通", 50 }, 51 }, 52 } 53 for _, tt := range tests { 54 t.Run(tt.name, func(t *testing.T) { 55 c := New(Option{ 56 Retry: 1, 57 Logger: logger, 58 Timeout: time.Second, 59 }) 60 got, err := c.QueryIP(tt.args.ctx, tt.args.ip) 61 if (err != nil) != tt.wantErr { 62 t.Errorf("QueryIP() error = %v, wantErr %v", err, tt.wantErr) 63 return 64 } 65 if !reflect.DeepEqual(got, tt.want) { 66 t.Errorf("QueryIP() got = %v, want %v", got, tt.want) 67 } 68 }) 69 } 70 }