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
|
package grpc
import (
"context"
"log"
"testing"
"time"
"yats/internal/proto"
"google.golang.org/grpc"
)
func TestGrpcCreateMetric(t *testing.T) {
conn, err := grpc.Dial("localhost:50051", grpc.WithInsecure(), grpc.WithBlock())
if err != nil {
log.Fatalf("did not connect: %v", err)
}
defer conn.Close()
c := proto.NewYatsGrpcServiceClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
item := &proto.Metric{Name: "testMetric1", Mtime: time.Now().UnixMilli(), Value: "This is the value"}
res, err := c.CreateMetric(ctx, &proto.CreateMetricRequest{Metric: item})
if err != nil {
log.Fatalf("could not create metric: %v", err)
}
log.Printf("Metric created: %v", res.GetMetric())
}
func TestGrpcCreateEvent(t *testing.T) {
conn, err := grpc.Dial("localhost:50051", grpc.WithInsecure(), grpc.WithBlock())
if err != nil {
log.Fatalf("did not connect: %v", err)
}
defer conn.Close()
c := proto.NewYatsGrpcServiceClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
item := &proto.Event{Name: "testEvent1", Etime: time.Now().UnixMilli()}
res, err := c.CreateEvent(ctx, &proto.CreateEventRequest{Event: item})
if err != nil {
log.Fatalf("could not create event: %v", err)
}
log.Printf("Event created: %v", res.GetEvent())
}
|