github.com/kaydxh/golang@v0.0.131/go/net/http/example/http_client.repository_test.go (about) 1 package date_test 2 3 import ( 4 "testing" 5 "time" 6 7 "context" 8 9 http_ "github.com/kaydxh/golang/go/net/http" 10 date_ "github.com/kaydxh/golang/go/net/http/example" 11 ) 12 13 func TestNowPbJson(t *testing.T) { 14 15 ctx := context.Background() 16 client, err := http_.NewClient() 17 if err != nil { 18 t.Errorf("failed to new http client, err: %v", err) 19 } 20 factory, err := http_.NewFactory[date_.NowRequest, date_.NowResponse](http_.FactoryConfig{ 21 Url: "http://localhost:10001/Now", 22 Timeout: 5 * time.Second, 23 Client: client, 24 RetryTimes: 3, 25 }, 26 ) 27 if err != nil { 28 t.Errorf("failed to new factory, err: %v", err) 29 } 30 repository, err := factory.NewClient(ctx) 31 if err != nil { 32 t.Errorf("failed to new respository client, err: %v", err) 33 } 34 35 nowResponse, err := repository.PostPbJson(ctx, &date_.NowRequest{}) 36 if err != nil { 37 t.Errorf("failed to call Now, err: %v", err) 38 } 39 40 t.Logf("resp: %v", nowResponse) 41 42 } 43 44 func TestNowPb(t *testing.T) { 45 46 ctx := context.Background() 47 client, err := http_.NewClient() 48 if err != nil { 49 t.Errorf("failed to new http client, err: %v", err) 50 } 51 factory, err := http_.NewFactory[date_.NowRequest, date_.NowResponse](http_.FactoryConfig{ 52 Url: "http://localhost:10001/Now", 53 Timeout: 5 * time.Second, 54 Client: client, 55 RetryTimes: 3, 56 }, 57 ) 58 if err != nil { 59 t.Errorf("failed to new factory, err: %v", err) 60 } 61 repository, err := factory.NewClient(ctx) 62 if err != nil { 63 t.Errorf("failed to new respository client, err: %v", err) 64 } 65 66 nowResponse, err := repository.PostPb(ctx, &date_.NowRequest{}) 67 if err != nil { 68 t.Errorf("failed to call Now, err: %v", err) 69 } 70 71 t.Logf("resp: %v", nowResponse) 72 73 }