2025-06-14 23:18:05 +07:00

58 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package tests
import (
"context"
"log"
"testing"
"time"
"evening_detective/internal/config"
"evening_detective/internal/services"
pb "evening_detective/proto"
"github.com/stretchr/testify/assert"
"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)
}
func deleteTeams(t *testing.T) {
dbFilepath := config.GetDBFilepath()
repository, err := services.NewRepository(dbFilepath)
if err != nil {
assert.Nil(t, err, "подключение к базе")
}
defer repository.Close()
err = repository.DeleteAllTeams(context.Background())
assert.Nil(t, err, "команды удалены")
}
func createTeam(client pb.EveningDetectiveClient, name string) (*pb.AddTeamsRsp, error) {
ctx, cancel := getContext()
defer cancel()
req := &pb.AddTeamsReq{
Teams: []*pb.Team{
{Name: name},
},
}
return client.AddTeams(ctx, req)
}
func getTeams(client pb.EveningDetectiveClient) (*pb.GetTeamsRsp, error) {
ctx, cancel := getContext()
defer cancel()
req := &pb.GetTeamsReq{}
return client.GetTeams(ctx, req)
}