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

53 lines
1.2 KiB
Go
Raw Normal View History

2025-01-21 18:24:14 +00:00
package client_test
import (
"context"
"errors"
"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 TestGet(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
id := uuid.New()
pool.ExpectQuery("name: GetClient :one").WithArgs(database.MustToDBUUID(id)).
WillReturnRows(
pgxmock.NewRows([]string{"id", "name", "canSync"}).
AddRow(database.MustToDBUUID(id), "client_name", false),
)
cli, err := svc.Get(ctx, id)
assert.NoError(t, err)
2025-01-21 18:24:14 +00:00
assert.EqualExportedValues(t, &client.Client{
ID: id,
Name: "client_name",
CanSync: false,
}, cli)
dberr := "database failure"
pool.ExpectQuery("name: GetClient :one").WithArgs(database.MustToDBUUID(id)).
WillReturnError(errors.New(dberr))
_, err = svc.Get(ctx, id)
assert.EqualError(t, err, dberr)
}