ed8cfbbee4
Set Collector * set
42 lines
897 B
Go
42 lines
897 B
Go
package client_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"queryorchestration/internal/client"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/serviceconfig"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestCreate(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)
|
|
|
|
svc := client.New(cfg)
|
|
|
|
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)
|
|
assert.Equal(t, aid, id)
|
|
}
|