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