servicechecker/pkg/protoset/protoset_test.go
Gorbunov Kirill Andreevich 2b7fc78872 #1-add protoset
2024-11-21 15:03:07 +03:00

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)
})
}