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"
2025-03-05 12:05:46 +00:00
"testing"
2025-01-21 18:24:14 +00:00
"queryorchestration/internal/client"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/serviceconfig"
2025-01-21 18:24:14 +00:00
"github.com/google/uuid"
"github.com/pashagolub/pgxmock/v3"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
2025-01-21 18:24:14 +00:00
)
func TestGet(t *testing.T) {
ctx := context.Background()
pool, err := pgxmock.NewPool()
require.NoError(t, 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)
}