51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
|
package protoset
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
"os"
|
||
|
"testing"
|
||
|
|
||
|
. "github.com/smartystreets/goconvey/convey"
|
||
|
"go.unistack.org/micro/v3/logger"
|
||
|
)
|
||
|
|
||
|
func TestProtoSet(t *testing.T) {
|
||
|
Convey("test1", t, func() {
|
||
|
ctx := context.Background()
|
||
|
p := NewProtoSet(logger.DefaultLogger)
|
||
|
data, err := os.ReadFile("/Users/kgorbunov/GolandProjects/src/card-proto/card-grpc.protoset")
|
||
|
So(err, ShouldBeNil)
|
||
|
|
||
|
err = p.AddProtoset(ctx, "localhost:9090", "CardService", data)
|
||
|
So(err, ShouldBeNil)
|
||
|
|
||
|
req, rsp, err := p.GetMessage(ctx, "localhost:9090", "card_proto", "CardService", "GetCardList")
|
||
|
So(err, ShouldBeNil)
|
||
|
fmt.Printf("req: %v, rsp: %v", req, rsp)
|
||
|
})
|
||
|
|
||
|
Convey("test2-bad", t, func() {
|
||
|
ctx := context.Background()
|
||
|
p := NewProtoSet(logger.DefaultLogger)
|
||
|
data, err := os.ReadFile("/Users/kgorbunov/GolandProjects/src/card-proto/card-grpc.protoset")
|
||
|
So(err, ShouldBeNil)
|
||
|
|
||
|
err = p.AddProtoset(ctx, "localhost:9090", "CardService", data)
|
||
|
So(err, ShouldBeNil)
|
||
|
|
||
|
req, rsp, err := p.GetMessage(ctx, "localhost:9090", "card_proto", "Card", "GetCardList")
|
||
|
So(err, ShouldBeError)
|
||
|
fmt.Printf("req: %v, rsp: %v", req, rsp)
|
||
|
})
|
||
|
|
||
|
Convey("test2-not-found", t, func() {
|
||
|
ctx := context.Background()
|
||
|
p := NewProtoSet(logger.DefaultLogger)
|
||
|
|
||
|
req, rsp, err := p.GetMessage(ctx, "localhost:9090", "card_proto", "CardService", "GetCardList")
|
||
|
So(err, ShouldEqual, errNotFound)
|
||
|
fmt.Printf("req: %v, rsp: %v", req, rsp)
|
||
|
})
|
||
|
}
|