Makefile: implement make db-tests
enables the option to run the DB tests locally that are executed in the github actions
This commit is contained in:
parent
1f8da3bd83
commit
00d3f07d08
8 changed files with 74 additions and 18 deletions
11
.github/workflows/tests.yml
vendored
11
.github/workflows/tests.yml
vendored
|
|
@ -79,14 +79,9 @@ jobs:
|
||||||
PGHOST: localhost
|
PGHOST: localhost
|
||||||
PGPORT: 5432
|
PGPORT: 5432
|
||||||
run: |
|
run: |
|
||||||
WORKDIR=$(readlink -f pkg/jobqueue/dbjobqueue/schemas)
|
./tools/dbtest-prepare-env.sh
|
||||||
pushd $(mktemp -d)
|
./tools/dbtest-run-migrations.sh
|
||||||
go mod init temp
|
- run: ./tools/dbtest-entrypoint.sh
|
||||||
go install github.com/jackc/tern@latest
|
|
||||||
$(go env GOPATH)/bin/tern migrate -m "$WORKDIR"
|
|
||||||
popd
|
|
||||||
- run: go test -tags=integration ./cmd/osbuild-composer-dbjobqueue-tests
|
|
||||||
- run: go test -tags=integration ./cmd/osbuild-service-maintenance
|
|
||||||
|
|
||||||
python-lint:
|
python-lint:
|
||||||
name: "🐍 Lint python scripts"
|
name: "🐍 Lint python scripts"
|
||||||
|
|
|
||||||
43
Makefile
43
Makefile
|
|
@ -19,6 +19,10 @@ SRCDIR ?= .
|
||||||
|
|
||||||
RST2MAN ?= rst2man
|
RST2MAN ?= rst2man
|
||||||
|
|
||||||
|
.ONESHELL:
|
||||||
|
SHELL := /bin/bash
|
||||||
|
.SHELLFLAGS := -ec -o pipefail
|
||||||
|
|
||||||
# see https://hub.docker.com/r/docker/golangci-lint/tags
|
# see https://hub.docker.com/r/docker/golangci-lint/tags
|
||||||
# v1.55 to get golang 1.21 (1.21.3)
|
# v1.55 to get golang 1.21 (1.21.3)
|
||||||
# v1.53 to get golang 1.20 (1.20.5)
|
# v1.53 to get golang 1.20 (1.20.5)
|
||||||
|
|
@ -164,7 +168,7 @@ install: build
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean: db-tests-prune
|
||||||
rm -rf $(BUILDDIR)/bin/
|
rm -rf $(BUILDDIR)/bin/
|
||||||
rm -rf $(CURDIR)/rpmbuild
|
rm -rf $(CURDIR)/rpmbuild
|
||||||
rm -rf container_composer_golangci_built.info
|
rm -rf container_composer_golangci_built.info
|
||||||
|
|
@ -236,7 +240,6 @@ worker-key-pair: ca
|
||||||
rm /etc/osbuild-composer/worker-csr.pem
|
rm /etc/osbuild-composer/worker-csr.pem
|
||||||
|
|
||||||
.PHONY: unit-tests
|
.PHONY: unit-tests
|
||||||
.ONESHELL:
|
|
||||||
unit-tests:
|
unit-tests:
|
||||||
go test -race -covermode=atomic -coverprofile=coverage.txt -coverpkg=$$(go list ./... | tr "\n" ",") ./...
|
go test -race -covermode=atomic -coverprofile=coverage.txt -coverpkg=$$(go list ./... | tr "\n" ",") ./...
|
||||||
# go modules with go.mod in subdirs are not tested automatically
|
# go modules with go.mod in subdirs are not tested automatically
|
||||||
|
|
@ -248,6 +251,42 @@ coverage-report: unit-tests
|
||||||
go tool cover -o coverage.html -html coverage.txt
|
go tool cover -o coverage.html -html coverage.txt
|
||||||
go tool cover -o coverage_splunk_logger.html -html coverage_splunk_logger.txt
|
go tool cover -o coverage_splunk_logger.html -html coverage_splunk_logger.txt
|
||||||
|
|
||||||
|
CONTAINER_EXECUTABLE ?= podman
|
||||||
|
|
||||||
|
.PHONY: db-tests-prune
|
||||||
|
db-tests-prune:
|
||||||
|
-$(CONTAINER_EXECUTABLE) stop composer-test-db
|
||||||
|
-$(CONTAINER_EXECUTABLE) rm composer-test-db
|
||||||
|
|
||||||
|
CHECK_DB_PORT_READY=$(CONTAINER_EXECUTABLE) exec composer-test-db pg_isready -d osbuildcomposer
|
||||||
|
CHECK_DB_UP=$(CONTAINER_EXECUTABLE) exec composer-test-db psql -U postgres -d osbuildcomposer -c "SELECT 1"
|
||||||
|
|
||||||
|
.PHONY: db-tests
|
||||||
|
db-tests:
|
||||||
|
-$(CONTAINER_EXECUTABLE) stop composer-test-db 2>/dev/null || echo "DB already stopped"
|
||||||
|
-$(CONTAINER_EXECUTABLE) rm composer-test-db 2>/dev/null || echo "DB already removed"
|
||||||
|
$(CONTAINER_EXECUTABLE) run -d \
|
||||||
|
--name composer-test-db \
|
||||||
|
--env POSTGRES_PASSWORD=foobar \
|
||||||
|
--env POSTGRES_DB=osbuildcomposer \
|
||||||
|
--publish 5432:5432 \
|
||||||
|
postgres:12
|
||||||
|
echo "Waiting for DB"
|
||||||
|
until $(CHECK_DB_PORT_READY) ; do sleep 1; done
|
||||||
|
until $(CHECK_DB_UP) ; do sleep 1; done
|
||||||
|
env PGPASSWORD=foobar \
|
||||||
|
PGDATABASE=osbuildcomposer \
|
||||||
|
PGUSER=postgres \
|
||||||
|
PGHOST=localhost \
|
||||||
|
PGPORT=5432 \
|
||||||
|
./tools/dbtest-run-migrations.sh
|
||||||
|
./tools/dbtest-entrypoint.sh
|
||||||
|
# we'll leave the composer-test-db container running
|
||||||
|
# for easier inspection is something fails
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
|
test: unit-tests db-tests # run all tests
|
||||||
|
|
||||||
#
|
#
|
||||||
# Building packages
|
# Building packages
|
||||||
#
|
#
|
||||||
|
|
|
||||||
|
|
@ -14,12 +14,10 @@ import (
|
||||||
"github.com/osbuild/osbuild-composer/internal/jobqueue/jobqueuetest"
|
"github.com/osbuild/osbuild-composer/internal/jobqueue/jobqueuetest"
|
||||||
)
|
)
|
||||||
|
|
||||||
const url = "postgres://postgres:foobar@localhost:5432/osbuildcomposer"
|
|
||||||
|
|
||||||
func TestJobQueueInterface(t *testing.T) {
|
func TestJobQueueInterface(t *testing.T) {
|
||||||
makeJobQueue := func() (jobqueue.JobQueue, func(), error) {
|
makeJobQueue := func() (jobqueue.JobQueue, func(), error) {
|
||||||
// clear db before each run
|
// clear db before each run
|
||||||
conn, err := pgx.Connect(context.Background(), url)
|
conn, err := pgx.Connect(context.Background(), jobqueuetest.TestDbURL())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -35,7 +33,7 @@ func TestJobQueueInterface(t *testing.T) {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
q, err := dbjobqueue.New(url)
|
q, err := dbjobqueue.New(jobqueuetest.TestDbURL())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"github.com/osbuild/osbuild-composer/internal/jobqueue/jobqueuetest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
|
@ -13,13 +14,11 @@ import (
|
||||||
"github.com/osbuild/osbuild-composer/pkg/jobqueue/dbjobqueue"
|
"github.com/osbuild/osbuild-composer/pkg/jobqueue/dbjobqueue"
|
||||||
)
|
)
|
||||||
|
|
||||||
const url = "postgres://postgres:foobar@localhost:5432/osbuildcomposer"
|
|
||||||
|
|
||||||
func TestDBJobQueueMaintenance(t *testing.T) {
|
func TestDBJobQueueMaintenance(t *testing.T) {
|
||||||
dbMaintenance, err := newDB(url)
|
dbMaintenance, err := newDB(jobqueuetest.TestDbURL())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer dbMaintenance.Close()
|
defer dbMaintenance.Close()
|
||||||
q, err := dbjobqueue.New(url)
|
q, err := dbjobqueue.New(jobqueuetest.TestDbURL())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer q.Close()
|
defer q.Close()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ package jobqueuetest
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -20,6 +22,14 @@ type MakeJobQueue func() (q jobqueue.JobQueue, stop func(), err error)
|
||||||
type testResult struct {
|
type testResult struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDbURL() string {
|
||||||
|
host := os.Getenv("COMPOSER_TEST_DB_HOST")
|
||||||
|
if host == "" {
|
||||||
|
host = "localhost"
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("postgres://postgres:foobar@%s:5432/osbuildcomposer", host)
|
||||||
|
}
|
||||||
|
|
||||||
func TestJobQueue(t *testing.T, makeJobQueue MakeJobQueue) {
|
func TestJobQueue(t *testing.T, makeJobQueue MakeJobQueue) {
|
||||||
wrap := func(f func(t *testing.T, q jobqueue.JobQueue)) func(*testing.T) {
|
wrap := func(f func(t *testing.T, q jobqueue.JobQueue)) func(*testing.T) {
|
||||||
q, stop, err := makeJobQueue()
|
q, stop, err := makeJobQueue()
|
||||||
|
|
|
||||||
5
tools/dbtest-entrypoint.sh
Executable file
5
tools/dbtest-entrypoint.sh
Executable file
|
|
@ -0,0 +1,5 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
go version
|
||||||
|
go test -tags=integration ./cmd/osbuild-composer-dbjobqueue-tests
|
||||||
|
go test -tags=integration ./cmd/osbuild-service-maintenance
|
||||||
6
tools/dbtest-prepare-env.sh
Executable file
6
tools/dbtest-prepare-env.sh
Executable file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
pushd $(mktemp -d)
|
||||||
|
go mod init temp
|
||||||
|
go install github.com/jackc/tern@latest
|
||||||
|
popd
|
||||||
4
tools/dbtest-run-migrations.sh
Executable file
4
tools/dbtest-run-migrations.sh
Executable file
|
|
@ -0,0 +1,4 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
WORKDIR=$(readlink -f pkg/jobqueue/dbjobqueue/schemas)
|
||||||
|
$(go env GOPATH)/bin/tern migrate -m "$WORKDIR"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue