d91ef1832b
Function Test Coverage * test * scripts
84 lines
2.0 KiB
Go
84 lines
2.0 KiB
Go
package job_test
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/job"
|
|
"queryorchestration/internal/serviceconfig"
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestGetStatus(t *testing.T) {
|
|
t.Run("is synced", func(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{})
|
|
|
|
jobId := uuid.New()
|
|
|
|
pool.ExpectQuery("name: IsJobSynced :one").WithArgs(database.MustToDBUUID(jobId)).WillReturnRows(
|
|
pgxmock.NewRows([]string{"issynced"}).
|
|
AddRow(true),
|
|
)
|
|
|
|
issynced, err := svc.GetStatus(ctx, jobId)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, job.IN_SYNC, *issynced)
|
|
})
|
|
t.Run("not synced", func(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{})
|
|
|
|
jobId := uuid.New()
|
|
|
|
pool.ExpectQuery("name: IsJobSynced :one").WithArgs(database.MustToDBUUID(jobId)).WillReturnRows(
|
|
pgxmock.NewRows([]string{"issynced"}).
|
|
AddRow(false),
|
|
)
|
|
|
|
issynced, err := svc.GetStatus(ctx, jobId)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, job.NOT_SYNCED, *issynced)
|
|
})
|
|
t.Run("db error", func(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{})
|
|
|
|
jobId := uuid.New()
|
|
|
|
errStr := "db fail"
|
|
pool.ExpectQuery("name: IsJobSynced :one").WithArgs(database.MustToDBUUID(jobId)).
|
|
WillReturnError(errors.New(errStr))
|
|
|
|
_, err = svc.GetStatus(ctx, jobId)
|
|
assert.EqualError(t, err, errStr)
|
|
})
|
|
}
|