Files
query-orchestration/internal/client/status_test.go
T
Michael McGuinness 7ce7c9df4d Merged in feature/ecr (pull request #161)
Feature/ecr

* nosave

* repo

* awscli

* unzip

* ignore

* moreram

* 14k

* ref

* deployment

* 12k

* uselocal

* go

* dockercomd

* reorder

* iamgename

* installs

* tart

* cli

* clideps

* y

* dockerce

* nodock

* multi

* rmecr

* dev
2025-06-03 13:52:10 +00:00

76 lines
2.1 KiB
Go

package client_test
import (
"errors"
"testing"
"queryorchestration/internal/client"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/serviceconfig"
"github.com/pashagolub/pgxmock/v3"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGetStatus(t *testing.T) {
ctx := t.Context()
pool, err := pgxmock.NewPool()
require.NoError(t, err)
cfg := &serviceconfig.BaseConfig{}
cfg.DBPool = pool
cfg.DBQueries = repository.New(pool)
svc := client.New(cfg)
clientId := "clientid"
t.Run("is synced", func(t *testing.T) {
pool.ExpectQuery("name: GetClient :one").WithArgs(clientId).WillReturnRows(
pgxmock.NewRows([]string{"id", "name", "can_sync"}).
AddRow(clientId, "name", true),
)
pool.ExpectQuery("name: IsClientSynced :one").WithArgs(&clientId).WillReturnRows(
pgxmock.NewRows([]string{"issynced"}).
AddRow(true),
)
issynced, err := svc.GetStatus(ctx, clientId)
require.NoError(t, err)
assert.Equal(t, client.IN_SYNC, issynced)
})
t.Run("not synced", func(t *testing.T) {
pool.ExpectQuery("name: GetClient :one").WithArgs(clientId).WillReturnRows(
pgxmock.NewRows([]string{"clientId", "name", "can_sync"}).
AddRow(clientId, "name", true),
)
pool.ExpectQuery("name: IsClientSynced :one").WithArgs(&clientId).WillReturnRows(
pgxmock.NewRows([]string{"issynced"}).
AddRow(false),
)
issynced, err := svc.GetStatus(ctx, clientId)
require.NoError(t, err)
assert.Equal(t, client.NOT_SYNCED, issynced)
})
t.Run("not syncing", func(t *testing.T) {
pool.ExpectQuery("name: GetClient :one").WithArgs(clientId).WillReturnRows(
pgxmock.NewRows([]string{"clientId", "name", "can_sync"}).
AddRow(clientId, "name", false),
)
issynced, err := svc.GetStatus(ctx, clientId)
require.NoError(t, err)
assert.Equal(t, client.NOT_SYNCING, issynced)
})
t.Run("db error", func(t *testing.T) {
errStr := "db fail"
pool.ExpectQuery("name: GetClient :one").WithArgs(clientId).
WillReturnError(errors.New(errStr))
_, err = svc.GetStatus(ctx, clientId)
assert.EqualError(t, err, errStr)
})
}