debian-forge-composer/cmd/osbuild-composer-dbjobqueue-tests/main_test.go
Florian Schüller 00d3f07d08 Makefile: implement make db-tests
enables the option to run the DB tests locally
that are executed in the github actions
2024-11-06 15:16:42 +01:00

47 lines
1.1 KiB
Go

//go: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"
)
func TestJobQueueInterface(t *testing.T) {
makeJobQueue := func() (jobqueue.JobQueue, func(), error) {
// clear db before each run
conn, err := pgx.Connect(context.Background(), jobqueuetest.TestDbURL())
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(jobqueuetest.TestDbURL())
if err != nil {
return nil, nil, err
}
stop := func() {
q.Close()
}
return q, stop, nil
}
jobqueuetest.TestJobQueue(t, makeJobQueue)
}