add a test-cli to run smoke tests manually
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
parent
5da1f85b76
commit
0cb633c4df
3 changed files with 2517 additions and 0 deletions
6
src/test-cli/genproto.sh
Executable file
6
src/test-cli/genproto.sh
Executable file
|
@ -0,0 +1,6 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
PATH=$PATH:$GOPATH/bin
|
||||
protodir=../../pb
|
||||
|
||||
protoc --go_out=plugins=grpc:genproto -I $protodir $protodir/demo.proto
|
2433
src/test-cli/genproto/demo.pb.go
Normal file
2433
src/test-cli/genproto/demo.pb.go
Normal file
File diff suppressed because it is too large
Load diff
78
src/test-cli/main.go
Normal file
78
src/test-cli/main.go
Normal file
|
@ -0,0 +1,78 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
pb "./genproto"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type test struct {
|
||||
envs []string
|
||||
f func() error
|
||||
}
|
||||
|
||||
var (
|
||||
svcs = map[string]test{
|
||||
"productcatalogservice": {
|
||||
envs: []string{"PRODUCT_CATALOG_SERVICE_ADDR"},
|
||||
f: testProductCatalogService,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) != 2 {
|
||||
panic("incorrect usage")
|
||||
}
|
||||
t, ok := svcs[os.Args[1]]
|
||||
if !ok {
|
||||
log.Fatalf("test probe for %q not found", os.Args[1])
|
||||
}
|
||||
for _, e := range t.envs {
|
||||
if os.Getenv(e) == "" {
|
||||
log.Fatalf("environment variable %q not set", e)
|
||||
}
|
||||
}
|
||||
if err := t.f(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
log.Println("PASS")
|
||||
}
|
||||
|
||||
func testProductCatalogService() error {
|
||||
addr := os.Getenv("PRODUCT_CATALOG_SERVICE_ADDR")
|
||||
conn, err := grpc.Dial(addr, grpc.WithInsecure())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
log.Printf("--- rpc ListProducts() ")
|
||||
cl := pb.NewProductCatalogServiceClient(conn)
|
||||
listResp, err := cl.ListProducts(context.TODO(), &pb.Empty{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Printf("--> %d products returned", len(listResp.GetProducts()))
|
||||
for _, v := range listResp.GetProducts() {
|
||||
log.Printf("--> %+v", v)
|
||||
}
|
||||
|
||||
log.Println("--- rpc GetProduct()")
|
||||
getResp, err := cl.GetProduct(context.TODO(), &pb.GetProductRequest{Id: 1})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Printf("retrieved product: %+v", getResp)
|
||||
log.Printf("--- rpc SearchProducts()")
|
||||
searchResp, err := cl.SearchProducts(context.TODO(), &pb.SearchProductsRequest{Query: "shirt"})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Printf("--> %d results found", len(searchResp.GetResults()))
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Reference in a new issue