4ec1d51a12
Job CRUD + Collector Integration * startedcreate * openapispec * createjobintegration * jobgetcontroller * jobcreateclient * updatejob * job * collector
54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
package repository_test
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/test"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestJob(t *testing.T) {
|
|
ctx := context.Background()
|
|
db, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
|
Migrations: &database.MigrationConfig{
|
|
BasePath: path.Join(os.Getenv("PWD"), "../../.."),
|
|
}})
|
|
defer cleanup()
|
|
|
|
queries := repository.New(db.Pool)
|
|
|
|
clientId, err := queries.CreateClient(ctx, "example_client")
|
|
assert.Nil(t, err)
|
|
|
|
id, err := queries.CreateJob(ctx, clientId)
|
|
assert.Nil(t, err)
|
|
assert.NotEmpty(t, id)
|
|
|
|
job, err := queries.GetJob(ctx, id)
|
|
assert.Nil(t, err)
|
|
assert.EqualExportedValues(t, &repository.Job{
|
|
ID: id,
|
|
Clientid: clientId,
|
|
Cansync: false,
|
|
}, job)
|
|
|
|
err = queries.UpdateJob(ctx, &repository.UpdateJobParams{
|
|
Cansync: true,
|
|
ID: id,
|
|
})
|
|
assert.Nil(t, err)
|
|
|
|
job, err = queries.GetJob(ctx, id)
|
|
assert.Nil(t, err)
|
|
assert.EqualExportedValues(t, &repository.Job{
|
|
ID: id,
|
|
Clientid: clientId,
|
|
Cansync: true,
|
|
}, job)
|
|
}
|