generated from VLADIMIR/template
add tests
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
pb "evening_detective/proto"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func getClient() (pb.EveningDetectiveClient, func() error) {
|
||||
conn, err := grpc.Dial("localhost:8080", grpc.WithInsecure())
|
||||
if err != nil {
|
||||
log.Fatalf("Не удалось подключиться к серверу: %v", err)
|
||||
}
|
||||
return pb.NewEveningDetectiveClient(conn), conn.Close
|
||||
}
|
||||
|
||||
func getContext() (context.Context, context.CancelFunc) {
|
||||
return context.WithTimeout(context.Background(), time.Second)
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"log"
|
||||
"testing"
|
||||
|
||||
pb "evening_detective/proto"
|
||||
)
|
||||
|
||||
func TestPing(t *testing.T) {
|
||||
client, close := getClient()
|
||||
defer close()
|
||||
|
||||
ctx, cancel := getContext()
|
||||
defer cancel()
|
||||
|
||||
req := &pb.PingReq{}
|
||||
|
||||
_, err := client.Ping(ctx, req)
|
||||
if err != nil {
|
||||
log.Fatalf("Ошибка выполнения запроса: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user