d91ef1832b
Function Test Coverage * test * scripts
54 lines
1.5 KiB
Go
54 lines
1.5 KiB
Go
package job_test
|
|
|
|
import (
|
|
"context"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/job"
|
|
"queryorchestration/internal/job/collector"
|
|
"queryorchestration/internal/serviceconfig"
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5"
|
|
"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 := job.New(cfg, &job.Services{
|
|
Collector: collector.New(cfg, &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: AddLatestCollectorVersion :one").WithArgs(database.MustToDBUUID(job.ID)).WillReturnRows(
|
|
pgxmock.NewRows([]string{"version"}).
|
|
AddRow(int32(1)),
|
|
)
|
|
pool.ExpectExec("name: SetActiveCollectorVersion :exec").WithArgs(database.MustToDBUUID(job.ID), int32(1)).
|
|
WillReturnResult(pgxmock.NewResult("", 1))
|
|
pool.ExpectCommit()
|
|
|
|
aid, err := svc.Create(ctx, job.ClientID)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, job.ID, aid)
|
|
}
|