add tests

This commit is contained in:
Владимир Фёдоров 2025-06-13 13:01:18 +07:00
parent 2fa0be8bcb
commit b852bebd63
3 changed files with 49 additions and 0 deletions

View File

@ -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
View 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)
}

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