debian-forge-composer/cmd/osbuild-composer-dbjobqueue-tests/main_test.go

50 lines
1.1 KiB
Go

//go:build integration
// +build integration
package main
import (
"context"
"fmt"
"testing"
"github.com/jackc/pgx/v4"
"github.com/osbuild/osbuild-composer/pkg/jobqueue"
"github.com/osbuild/osbuild-composer/pkg/jobqueue/dbjobqueue"
"github.com/osbuild/osbuild-composer/internal/jobqueue/jobqueuetest"
)
const url = "postgres://postgres:foobar@localhost:5432/osbuildcomposer"
func TestJobQueueInterface(t *testing.T) {
makeJobQueue := func() (jobqueue.JobQueue, func(), error) {
// clear db before each run
conn, err := pgx.Connect(context.Background(), url)
if err != nil {
return nil, nil, err
}
defer conn.Close(context.Background())
for _, table := range []string{"job_dependencies", "heartbeats", "jobs"} {
_, err = conn.Exec(context.Background(), fmt.Sprintf("DELETE FROM %s", table))
if err != nil {
return nil, nil, err
}
}
err = conn.Close(context.Background())
if err != nil {
return nil, nil, err
}
q, err := dbjobqueue.New(url)
if err != nil {
return nil, nil, err
}
stop := func() {
q.Close()
}
return q, stop, nil
}
jobqueuetest.TestJobQueue(t, makeJobQueue)
}