4ec1d51a12
Job CRUD + Collector Integration * startedcreate * openapispec * createjobintegration * jobgetcontroller * jobcreateclient * updatejob * job * collector
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package job_test
|
|
|
|
import (
|
|
"context"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/job"
|
|
"queryorchestration/internal/job/collector"
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5"
|
|
"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 := job.New(db, &job.Services{
|
|
Collector: collector.New(db, &collector.Services{}),
|
|
})
|
|
|
|
job := job.Job{
|
|
ID: uuid.New(),
|
|
ClientID: uuid.New(),
|
|
}
|
|
|
|
pool.ExpectQuery("name: CreateJob :one").WithArgs(database.MustToDBUUID(job.ClientID)).WillReturnRows(
|
|
pgxmock.NewRows([]string{"id"}).
|
|
AddRow(database.MustToDBUUID(job.ID)),
|
|
)
|
|
pool.ExpectBeginTx(pgx.TxOptions{})
|
|
pool.ExpectQuery("name: CreateCollector :one").WithArgs(database.MustToDBUUID(job.ID)).WillReturnRows(
|
|
pgxmock.NewRows([]string{"id"}).
|
|
AddRow(database.MustToDBUUID(uuid.New())),
|
|
)
|
|
pool.ExpectCommit()
|
|
|
|
aid, err := svc.Create(ctx, job.ClientID)
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, job.ID, aid)
|
|
}
|