04d8eaf52c
Client Entity * repolevel * servicefunctions * openapiclientget * openapiupdate * client * vendor
43 lines
866 B
Go
43 lines
866 B
Go
package client_test
|
|
|
|
import (
|
|
"context"
|
|
"queryorchestration/internal/client"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
"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)
|
|
}
|
|
queries := repository.New(pool)
|
|
db := &database.Connection{
|
|
Queries: queries,
|
|
Pool: pool,
|
|
}
|
|
|
|
svc := client.New(db)
|
|
|
|
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.Nil(t, err)
|
|
assert.Equal(t, aid, id)
|
|
}
|