Files
query-orchestration/internal/client/get_test.go
T
Jay Brown 15adaebfcd Merged in feature/serviceconfig-integration (pull request #38)
DRAFT PR : WIP working through ideas for integration

* movearound

* attempttwo

* openapi

* further sanding

* fix

* start on tests

* runthroughsingleconfig

* somechanges

* reflectissue

* removeerrs

* mostlyremovepanic

* removeenv

* noncfgtests

* go

* repo

* fix service config test

* add PWD to all

* test fix

* fix lint

* todo for later

* passingunittests

* alltests

* testlogger

* testloggername

* clean
2025-01-31 13:43:55 +00:00

53 lines
1.2 KiB
Go

package client_test
import (
"context"
"errors"
"queryorchestration/internal/client"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/serviceconfig"
"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)
svc := client.New(cfg)
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.Nil(t, err)
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)
}