Skip to content

Commit 6e338ae

Browse files
test: run tests on other BSD virtual machines (#624)
1 parent cc83d53 commit 6e338ae

22 files changed

Lines changed: 235 additions & 45 deletions

.github/workflows/build.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ jobs:
7272
test-ssh:
7373
name: Test SSH client
7474
runs-on: ubuntu-latest
75-
7675
steps:
7776
- name: Check out code into the Go module directory
7877
uses: actions/checkout@v6

.github/workflows/test.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Run tests on BSDs
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
test-freebsd:
8+
name: Run tests on FreeBSD
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
freebsd_version: ['14.3', '15.0']
13+
env:
14+
GO_VERSION: '1.26.2'
15+
steps:
16+
- uses: actions/checkout@v6
17+
18+
- name: Test
19+
uses: cross-platform-actions/action@v0.32.0
20+
with:
21+
operating_system: freebsd
22+
version: '${{ matrix.freebsd_version }}'
23+
memory: 15G
24+
cpu_count: 4
25+
environment_variables: GO_VERSION
26+
run: |
27+
curl -LO "https://go.dev/dl/go${GO_VERSION}.freebsd-amd64.tar.gz"
28+
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go${GO_VERSION}.freebsd-amd64.tar.gz
29+
export PATH=$PATH:/usr/local/go/bin
30+
go version
31+
pwd
32+
go build ./...
33+
go test -v -short ./...
34+
35+
test-netbsd:
36+
name: Run tests on NetBSD
37+
runs-on: ubuntu-latest
38+
strategy:
39+
matrix:
40+
netbsd_version: ['10.1']
41+
env:
42+
GO_VERSION: '1.26.2'
43+
steps:
44+
- uses: actions/checkout@v6
45+
46+
- name: Test
47+
uses: cross-platform-actions/action@v0.32.0
48+
with:
49+
operating_system: netbsd
50+
version: '${{ matrix.netbsd_version }}'
51+
memory: 15G
52+
cpu_count: 4
53+
environment_variables: GO_VERSION
54+
run: |
55+
curl -LO "https://go.dev/dl/go${GO_VERSION}.netbsd-amd64.tar.gz"
56+
sudo mkdir -p /usr/local
57+
sudo rm -rf /usr/local/go
58+
sudo tar -C /usr/local -xzf go${GO_VERSION}.netbsd-amd64.tar.gz
59+
export PATH=$PATH:/usr/local/go/bin
60+
go version
61+
pwd
62+
go build ./...
63+
go test -v -short ./...
64+
65+
test-openbsd:
66+
name: Run tests on OpenBSD
67+
runs-on: ubuntu-latest
68+
strategy:
69+
matrix:
70+
openbsd_version: ['7.8']
71+
env:
72+
GO_VERSION: '1.26.2'
73+
steps:
74+
- uses: actions/checkout@v6
75+
76+
- name: Test
77+
uses: cross-platform-actions/action@v0.32.0
78+
with:
79+
operating_system: openbsd
80+
version: '${{ matrix.openbsd_version }}'
81+
memory: 15G
82+
cpu_count: 4
83+
environment_variables: GO_VERSION
84+
run: |
85+
curl -LO "https://go.dev/dl/go${GO_VERSION}.openbsd-amd64.tar.gz"
86+
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go${GO_VERSION}.openbsd-amd64.tar.gz
87+
export PATH=$PATH:/usr/local/go/bin
88+
go version
89+
pwd
90+
go build ./...
91+
go test -v -short ./...

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ go.work.sum
4646

4747
/*.txt
4848
output.xml
49+
/qemu/disk_images/

codecov.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
ignore:
2+
- crond/mock/
23
- shell/mock/
34
- lock/test/
45
- priority/check/
@@ -15,6 +16,7 @@ ignore:
1516
- syslog_windows.go
1617
- schtasks/permission.go
1718
- user/user_systemd.go
19+
- qemu/
1820
- "**/mocks/*.go"
1921

2022
codecov:

crond/mock/main.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ func main() {
3535
sb := new(strings.Builder)
3636
if _, err := io.Copy(sb, os.Stdin); err == nil {
3737
if stdin := strings.TrimSpace(sb.String()); stdin != crontab {
38-
err = fmt.Errorf("%q != %q", crontab, stdin)
39-
if err != nil {
40-
fmt.Fprintln(os.Stderr, err)
41-
// os.Exit(1)
42-
}
38+
fmt.Fprintf(os.Stderr, "%q != %q\n", crontab, stdin)
4339
}
4440
}
4541
} else {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/creativeprojects/resticprofile
22

3-
go 1.26.1
3+
go 1.26.2
44

55
require (
66
github.com/Masterminds/semver/v3 v3.4.0

preventsleep/caffeinate_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build darwin || windows || linux
2+
13
package preventsleep_test
24

35
import (

qemu/main.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"log"
7+
"os"
8+
"os/exec"
9+
)
10+
11+
func main() {
12+
ctx := context.Background()
13+
err := runFreeBSD(ctx, "freebsd-15.0-arm64.qcow2")
14+
if err != nil {
15+
log.Fatal(err)
16+
}
17+
}
18+
19+
// func prepareFreeBSD(ctx context.Context, version string) error {
20+
// home, err := os.UserHomeDir()
21+
// if err != nil {
22+
// return fmt.Errorf("os.UserHomeDir: %w", err)
23+
// }
24+
// currentDir, err := os.Getwd()
25+
// if err != nil {
26+
// return fmt.Errorf("os.Getwd: %w", err)
27+
// }
28+
// err = unXZ(ctx,
29+
// filepath.Join(home, "Downloads", version+".xz"),
30+
// filepath.Join(currentDir, version),
31+
// )
32+
// if err != nil {
33+
// return fmt.Errorf("unXZ: %w", err)
34+
// }
35+
// return nil
36+
// }
37+
38+
// func unXZ(ctx context.Context, source, target string) error {
39+
// cmd := exec.CommandContext(ctx, "xz",
40+
// "--verbose",
41+
// "--keep",
42+
// "--decompress",
43+
// source,
44+
// )
45+
// cmd.Stdout = os.Stdout
46+
// cmd.Stderr = os.Stderr
47+
// err := cmd.Run()
48+
// if err != nil {
49+
// return fmt.Errorf("xz: %w", err)
50+
// }
51+
52+
// cmd = exec.CommandContext(ctx, "mv", "-v", strings.TrimSuffix(source, ".xz"), target)
53+
// cmd.Stdout = os.Stdout
54+
// cmd.Stderr = os.Stderr
55+
// err = cmd.Run()
56+
// if err != nil {
57+
// return fmt.Errorf("mv: %w", err)
58+
// }
59+
// return nil
60+
// }
61+
62+
func runFreeBSD(ctx context.Context, diskImage string) error {
63+
cmd := exec.CommandContext(ctx, "qemu-system-aarch64",
64+
"-m", "4096M", "-M", "virt,accel=hvf",
65+
"-cpu", "cortex-a57",
66+
"-bios", "edk2-aarch64-code.fd",
67+
"-rtc", "base=localtime,clock=rt",
68+
"-nographic",
69+
"-serial", "mon:stdio",
70+
"-device", "qemu-xhci",
71+
"-device", "usb-kbd",
72+
"-device", "usb-tablet",
73+
"-device", "virtio-net,netdev=net0",
74+
"-netdev", "user,id=net0,hostfwd=tcp::2222-:22,hostfwd=tcp::3389-:3389",
75+
"-drive", "if=virtio,file="+diskImage+",format=qcow2,cache=writethrough",
76+
)
77+
cmd.Stdin = os.Stdin
78+
cmd.Stdout = os.Stdout
79+
cmd.Stderr = os.Stderr
80+
err := cmd.Run()
81+
if err != nil {
82+
return fmt.Errorf("qemu-system-aarch64: %w", err)
83+
}
84+
return nil
85+
}
86+
87+
// curl -LO https://go.dev/dl/go1.26.2.freebsd-arm64.tar.gz
88+
// sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.26.2.freebsd-arm64.tar.gz
89+
// export PATH=$PATH:/usr/local/go/bin
90+
// go version

schedule/handler_bsd_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//go:build openbsd || netbsd || freebsd
2+
3+
package schedule
4+
5+
import (
6+
"testing"
7+
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
func TestHandlerDefaultOS(t *testing.T) {
12+
handler := NewHandler(SchedulerDefaultOS{})
13+
assert.IsType(t, &HandlerCrond{}, handler)
14+
}

schedule/handler_crond_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ import (
1515
"github.com/stretchr/testify/require"
1616
)
1717

18+
func TestHandlerCrond(t *testing.T) {
19+
handler := NewHandler(SchedulerCrond{})
20+
assert.IsType(t, &HandlerCrond{}, handler)
21+
}
22+
1823
func TestCreateReadDeleteCrondSchedules(t *testing.T) {
1924
hourly := calendar.NewEvent(func(e *calendar.Event) {
2025
e.Minute.MustAddValue(0)

0 commit comments

Comments
 (0)