-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflexgrpc_test.go
55 lines (47 loc) · 1.08 KB
/
flexgrpc_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package flexgrpc_test
import (
"context"
"reflect"
"testing"
"time"
"github.com/go-flexible/flexgrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/health/grpc_health_v1"
)
func TestHealthCheck(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
server := flexgrpc.New(&flexgrpc.Config{
Addr: ":50051",
})
go func() {
_ = server.Run(ctx)
}()
// give it time to start.
time.Sleep(time.Second)
conn, err := grpc.Dial("127.0.0.1:50051", grpc.WithInsecure())
if err != nil {
t.Error(err)
}
client := grpc_health_v1.NewHealthClient(conn)
res, err := client.Check(ctx, &grpc_health_v1.HealthCheckRequest{
Service: "",
})
if err != nil {
t.Error(err)
}
equal(t, "SERVING", res.Status.String())
}
func Example() {
srv := flexgrpc.New(
&flexgrpc.Config{Addr: ":8080"},
grpc.ConnectionTimeout(10*time.Second),
)
_ = srv.Run(context.Background())
}
func equal(t *testing.T, got, want interface{}) {
t.Helper()
if !reflect.DeepEqual(got, want) {
t.Fatalf("got: %#[1]v (%[1]T), but wanted: %#[2]v (%[2]T)", got, want)
}
}