Skip to content

Commit 708ed65

Browse files
Build BSD tests outside QEMU VM (#625)
1 parent 6e338ae commit 708ed65

38 files changed

Lines changed: 545 additions & 373 deletions

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export TEST_HELPERS=$(realpath build)/

.github/workflows/BSD-tests.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: Run tests on BSDs
2+
3+
on:
4+
workflow_dispatch:
5+
# push:
6+
# branches: [ master ]
7+
# paths-ignore:
8+
# - 'docs/**'
9+
10+
# pull_request:
11+
# types: [opened, synchronize, reopened]
12+
# paths-ignore:
13+
# - 'docs/**'
14+
15+
jobs:
16+
test-freebsd:
17+
name: Run tests on FreeBSD
18+
runs-on: ubuntu-latest
19+
strategy:
20+
matrix:
21+
freebsd_version: ['14.3', '15.0']
22+
steps:
23+
- uses: actions/checkout@v6
24+
25+
- name: Set up Go
26+
uses: actions/setup-go@v6
27+
with:
28+
go-version: "1.26"
29+
check-latest: true
30+
cache: true
31+
32+
- name: Build tests
33+
run: |
34+
make compile-tests
35+
env:
36+
GOOS: freebsd
37+
38+
- name: Run tests in VM
39+
uses: cross-platform-actions/action@v0.32.0
40+
with:
41+
operating_system: freebsd
42+
version: '${{ matrix.freebsd_version }}'
43+
memory: 8G
44+
cpu_count: 4
45+
run: |
46+
pwd
47+
./scripts/run-tests.sh
48+
49+
50+
test-netbsd:
51+
name: Run tests on NetBSD
52+
runs-on: ubuntu-latest
53+
strategy:
54+
matrix:
55+
netbsd_version: ['10.1']
56+
steps:
57+
- uses: actions/checkout@v6
58+
59+
- name: Set up Go
60+
uses: actions/setup-go@v6
61+
with:
62+
go-version: "1.26"
63+
check-latest: true
64+
cache: true
65+
66+
- name: Build tests
67+
run: |
68+
make compile-tests
69+
env:
70+
GOOS: netbsd
71+
72+
- name: Run tests in VM
73+
uses: cross-platform-actions/action@v0.32.0
74+
with:
75+
operating_system: netbsd
76+
version: '${{ matrix.netbsd_version }}'
77+
memory: 8G
78+
cpu_count: 4
79+
run: |
80+
pwd
81+
./scripts/run-tests.sh
82+
83+
84+
test-openbsd:
85+
name: Run tests on OpenBSD
86+
runs-on: ubuntu-latest
87+
strategy:
88+
matrix:
89+
openbsd_version: ['7.8']
90+
steps:
91+
- uses: actions/checkout@v6
92+
93+
- name: Set up Go
94+
uses: actions/setup-go@v6
95+
with:
96+
go-version: "1.26"
97+
check-latest: true
98+
cache: true
99+
100+
- name: Build tests
101+
run: |
102+
make compile-tests
103+
env:
104+
GOOS: openbsd
105+
106+
- name: Run tests in VM
107+
uses: cross-platform-actions/action@v0.32.0
108+
with:
109+
operating_system: openbsd
110+
version: '${{ matrix.openbsd_version }}'
111+
memory: 8G
112+
cpu_count: 4
113+
run: |
114+
pwd
115+
./scripts/run-tests.sh

.github/workflows/test.yml

Lines changed: 0 additions & 91 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
/examples/*-log.txt
77
/build/restic*
88
/build/rclone*
9+
/build/test-*
910
/dist
1011
/crontab
1112

@@ -47,3 +48,4 @@ go.work.sum
4748
/*.txt
4849
output.xml
4950
/qemu/disk_images/
51+
/*.test

Makefile

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ GOCLEAN=$(GOCMD) clean
99
GOTEST=$(GOCMD) test
1010
GOTOOL=$(GOCMD) tool
1111
GOMOD=$(GOCMD) mod
12+
GOGENERATE=$(GOCMD) generate
1213
GOPATH=$(shell $(GOCMD) env GOPATH)
1314
GOBIN=$(shell $(GOCMD) env GOBIN)
1415

@@ -31,7 +32,7 @@ COVERAGE_FILE=coverage.out
3132
COVERAGE_SSH_FILE=coverage-ssh.out
3233
JUNIT_FILE=unit-tests.xml
3334

34-
BUILD=build/
35+
BUILD=$(realpath build)/
3536

3637
RESTIC_GEN=$(BUILD)restic-generator
3738
RESTIC_DIR=$(BUILD)restic-
@@ -122,8 +123,27 @@ prepare_build: verify download
122123

123124
prepare_test: verify download $(GOBIN)/mockery ## Generate mocks
124125
@echo "[*] $@"
125-
find . -path "*/mocks/*" -exec rm {} \;
126-
"$(GOBIN)/mockery" --config .mockery.yml
126+
@find . -path "*/mocks/*" -exec rm {} \;
127+
@"$(GOBIN)/mockery" --config .mockery.yml
128+
129+
$(BUILD)test-args: ./testhelpers/args/*.go ## Build the test-args binary
130+
@echo "[*] $@"
131+
@$(GOBUILD) -v -o $(BUILD)test-args ./testhelpers/args
132+
133+
$(BUILD)test-echo: ./testhelpers/echo/*.go ## Build the test-echo binary
134+
@echo "[*] $@"
135+
@$(GOBUILD) -v -o $(BUILD)test-echo ./testhelpers/echo
136+
137+
$(BUILD)test-crontab: ./testhelpers/crontab/*.go ## Build the test-crontab binary
138+
@echo "[*] $@"
139+
@$(GOBUILD) -v -o $(BUILD)test-crontab ./testhelpers/crontab
140+
141+
$(BUILD)test-shell: ./testhelpers/shell/*.go ## Build the test-shell binary
142+
@echo "[*] $@"
143+
@$(GOBUILD) -v -o $(BUILD)test-shell ./testhelpers/shell
144+
145+
.PHONY: test-helpers
146+
test-helpers: $(BUILD)test-args $(BUILD)test-echo $(BUILD)test-crontab $(BUILD)test-shell ## Build all test helper binaries
127147

128148
download: verify ## Download dependencies
129149
@echo "[*] $@"
@@ -178,13 +198,26 @@ build-windows: prepare_build ## Build the binary for Windows
178198

179199
build-all: build-mac build-linux build-pi build-windows ## Build the binary for all platforms
180200

181-
test: $(GOBIN)/gotestsum prepare_test ## Run unit tests
201+
test: export TEST_HELPERS=$(BUILD)
202+
test: $(GOBIN)/gotestsum prepare_test test-helpers ## Run unit tests
203+
@echo "[*] $@"
204+
@$(GOBIN)/gotestsum -- -count=1 $(TESTS)
205+
206+
test-short: export TEST_HELPERS=$(BUILD)
207+
test-short: $(GOBIN)/gotestsum prepare_test test-helpers ## Run unit tests in short mode
182208
@echo "[*] $@"
183-
$(GOBIN)/gotestsum $(TESTS)
209+
@$(GOBIN)/gotestsum -- -short -count=1 $(TESTS)
184210

185-
test-ci: $(GOBIN)/gotestsum prepare_test ## Run unit tests with coverage (for CI)
211+
test-race: export TEST_HELPERS=$(BUILD)
212+
test-race: $(GOBIN)/gotestsum prepare_test test-helpers ## Run unit tests with race detector
186213
@echo "[*] $@"
187-
$(GOBIN)/gotestsum --junitfile $(JUNIT_FILE) -- -race -short -tags=fuse -coverprofile='$(COVERAGE_FILE)' ./...
214+
@$(GOBIN)/gotestsum -- -short -race -count=1 $(TESTS)
215+
216+
test-ci: export TEST_HELPERS=$(BUILD)
217+
test-ci: $(GOBIN)/gotestsum prepare_test test-helpers ## Run unit tests with coverage (for CI)
218+
@echo "[*] $@"
219+
@$(GOGENERATE) ./...
220+
@$(GOBIN)/gotestsum --junitfile $(JUNIT_FILE) -- -race -short -count=1 -tags=fuse -coverprofile='$(COVERAGE_FILE)' ./...
188221

189222
coverage: ## Generate coverage report
190223
@echo "[*] $@"
@@ -209,6 +242,11 @@ clean: ## Clean up the build artifacts
209242
restic_*_linux_amd64* \
210243
${BUILD}restic* \
211244
${BUILD}rclone* \
245+
${BUILD}test* \
246+
*.test \
247+
*.log \
248+
*.out \
249+
*.xml \
212250
dist/*
213251
find . -path "*/mocks/*" -exec rm {} \;
214252
restic cache --cleanup
@@ -385,3 +423,10 @@ stop-ssh-server: ## Stop the SSH server and clean up temporary files
385423
ssh-test: ## Run SSH client tests
386424
@echo "[*] $@"
387425
@go test -run TestSSHClient -v -race -tags ssh -coverprofile='$(COVERAGE_SSH_FILE)' ./ssh
426+
427+
.PHONY: compile-tests
428+
compile-tests: export TEST_HELPERS=$(BUILD)
429+
compile-tests: test-helpers ## Pre-compile all tests for running on BSD VMs
430+
@echo "[*] $@"
431+
@$(GOGENERATE) ./...
432+
@$(GOTEST) -c . ./batt ./calendar ./config/... ./crond ./dial ./filesearch ./lock ./monitor ./priority ./remote ./restic ./schedule ./shell ./ssh ./term ./user ./util/...

batt/battery.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !freebsd
2+
13
package batt
24

35
import (

batt/battery_freebsd.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//go:build freebsd
2+
3+
package batt
4+
5+
import (
6+
"github.com/distatus/battery"
7+
)
8+
9+
// Batteries return all connected batteries information
10+
func Batteries() ([]battery.Battery, error) {
11+
return nil, ErrBatteryInfoNotSupported
12+
}
13+
14+
// IsRunningOnBattery returns true if the computer is running on battery,
15+
// followed by the percentage of battery remaining. If no battery is present
16+
// the percentage will be 0.
17+
func IsRunningOnBattery() (bool, int, error) {
18+
return false, 0, ErrBatteryInfoNotSupported
19+
}

batt/battery_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !freebsd
2+
13
package batt
24

35
import (

batt/errors.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package batt
2+
3+
import "errors"
4+
5+
var ErrBatteryInfoNotSupported = errors.New("battery information is not supported on this platform")

codecov.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
ignore:
2-
- crond/mock/
3-
- shell/mock/
4-
- lock/test/
5-
- priority/check/
6-
- util/test_executable/
72
- term/remote.go
8-
- term/test/
93
- deprecation.go
104
- logger.go
115
- systemd.go
@@ -18,6 +12,7 @@ ignore:
1812
- user/user_systemd.go
1913
- qemu/
2014
- "**/mocks/*.go"
15+
- testhelpers/
2116

2217
codecov:
2318
notify:

0 commit comments

Comments
 (0)