test-cli: add smoke test for cartservice

Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
Ahmet Alp Balkan 2018-06-22 11:50:36 -07:00
parent 73a662cf83
commit 31adf1400c

View file

@ -40,6 +40,10 @@ var (
envs: []string{"CURRENCY_SERVICE_ADDR"}, envs: []string{"CURRENCY_SERVICE_ADDR"},
f: testCurrencyService, f: testCurrencyService,
}, },
"cartservice": {
envs: []string{"CART_SERVICE_ADDR"},
f: testCartService,
},
} }
) )
@ -285,3 +289,55 @@ func testCurrencyService() error {
log.Printf("--> in=%v result(USD): %+v", in, convertResp) log.Printf("--> in=%v result(USD): %+v", in, convertResp)
return nil return nil
} }
func testCartService() error {
addr := os.Getenv("CART_SERVICE_ADDR")
conn, err := grpc.Dial(addr, grpc.WithInsecure())
if err != nil {
return err
}
defer conn.Close()
cl := pb.NewCartServiceClient(conn)
// AddItem(ctx context.Context, in *AddItemRequest, opts ...grpc.CallOption) (*Empty, error)
// GetCart(ctx context.Context, in *GetCartRequest, opts ...grpc.CallOption) (*Cart, error)
// EmptyCart(ctx context.Context, in *EmptyCartRequest, opts ...grpc.CallOption) (*Empty, error)
log.Println("--- rpc AddItem()")
userID := "smoke-test-user"
_, err = cl.AddItem(context.TODO(), &pb.AddItemRequest{
UserId: userID,
Item: &pb.CartItem{ProductId: "1", Quantity: 2},
})
if err != nil {
return err
}
log.Printf("--> added item")
_, err = cl.AddItem(context.TODO(), &pb.AddItemRequest{
UserId: userID,
Item: &pb.CartItem{ProductId: "2", Quantity: 3},
})
if err != nil {
return err
}
log.Printf("--> added item")
log.Println("--- rpc GetCart()")
cartResp, err := cl.GetCart(context.TODO(), &pb.GetCartRequest{
UserId: userID})
if err != nil {
return err
}
log.Printf("--> %d items in cart for user %q", len(cartResp.Items), cartResp.UserId)
log.Printf("--> cart: %v", cartResp.Items)
log.Println("--- rpc EmptyCart()")
_, err = cl.EmptyCart(context.TODO(), &pb.EmptyCartRequest{
UserId: userID})
if err != nil {
return err
}
log.Printf("--> emptied the cart for user %q", userID)
return nil
}