7001ca854c
Queuing Changes and Cfg Testing * staarting * staarting * startedpush * note * save * mocking * removederrs * fixtests * cleanuperrs * newenvsetup * preppingtests * queue * mmovetocfgpassunittests * sortoutconfig * passinginteg * deps * fixtests
67 lines
1.4 KiB
Go
67 lines
1.4 KiB
Go
package repository_test
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/test"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestClient(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
cfg := test.CreateBaseConfig()
|
|
cfg.BasePath = path.Join(os.Getenv("PWD"), "../../..")
|
|
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
|
Cfg: cfg,
|
|
RunMigrations: true,
|
|
})
|
|
defer cleanup()
|
|
|
|
queries := cfg.DBQueries
|
|
|
|
id, err := queries.CreateClient(ctx, "example_client")
|
|
assert.NoError(t, err)
|
|
assert.NotEmpty(t, id)
|
|
|
|
client, err := queries.GetClient(ctx, id)
|
|
assert.NoError(t, err)
|
|
assert.EqualExportedValues(t, &repository.GetClientRow{
|
|
ID: id,
|
|
Name: "example_client",
|
|
Cansync: false,
|
|
}, client)
|
|
|
|
err = queries.UpdateClient(ctx, &repository.UpdateClientParams{
|
|
ID: id,
|
|
Name: "updated_client",
|
|
})
|
|
assert.NoError(t, err)
|
|
|
|
client, err = queries.GetClient(ctx, id)
|
|
assert.NoError(t, err)
|
|
assert.EqualExportedValues(t, &repository.GetClientRow{
|
|
ID: id,
|
|
Name: "updated_client",
|
|
Cansync: false,
|
|
}, client)
|
|
|
|
err = queries.AddClientCanSync(ctx, &repository.AddClientCanSyncParams{
|
|
Clientid: id,
|
|
Cansync: true,
|
|
})
|
|
assert.NoError(t, err)
|
|
|
|
client, err = queries.GetClient(ctx, id)
|
|
assert.NoError(t, err)
|
|
assert.EqualExportedValues(t, &repository.GetClientRow{
|
|
ID: id,
|
|
Name: "updated_client",
|
|
Cansync: true,
|
|
}, client)
|
|
}
|