generated from VLADIMIR/template
add tests
This commit is contained in:
parent
2fa0be8bcb
commit
b852bebd63
3
Makefile
3
Makefile
@ -18,3 +18,6 @@ build:
|
||||
text_to_story:
|
||||
rm -f ./cmd/text_to_story/story.json
|
||||
go run ./cmd/text_to_story/main.go
|
||||
|
||||
test:
|
||||
go test ./...
|
||||
|
23
internal/tests/client.go
Normal file
23
internal/tests/client.go
Normal file
@ -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)
|
||||
}
|
23
internal/tests/ping_test.go
Normal file
23
internal/tests/ping_test.go
Normal file
@ -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)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user