Files
query-orchestration/internal/client/create_test.go
T

42 lines
907 B
Go
Raw Normal View History

2025-01-21 18:24:14 +00:00
package client_test
import (
"context"
"queryorchestration/internal/client"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/serviceconfig"
2025-01-21 18:24:14 +00:00
"testing"
"github.com/google/uuid"
"github.com/pashagolub/pgxmock/v3"
"github.com/stretchr/testify/assert"
)
func TestCreate(t *testing.T) {
ctx := context.Background()
pool, err := pgxmock.NewPool()
if err != nil {
t.Fatalf("failed to open pgxmock database: %v", err)
}
cfg := &serviceconfig.BaseConfig{}
cfg.DBPool = pool
cfg.DBQueries = repository.New(pool)
2025-01-21 18:24:14 +00:00
svc := client.New(cfg)
2025-01-21 18:24:14 +00:00
name := "client_name"
aid := uuid.New()
pool.ExpectQuery("name: CreateClient :one").WithArgs(name).
WillReturnRows(
pgxmock.NewRows([]string{"id"}).
AddRow(database.MustToDBUUID(aid)),
)
id, err := svc.Create(ctx, name)
assert.NoError(t, err)
2025-01-21 18:24:14 +00:00
assert.Equal(t, aid, id)
}