Skip to content

Commit 66963a1

Browse files
authored
Merge pull request #464 from kolyshkin/go123
Bump go to 1.23, fix tests, add more images
2 parents 22a972e + 68e7373 commit 66963a1

File tree

7 files changed

+84
-32
lines changed

7 files changed

+84
-32
lines changed

.github/workflows/containers.yml

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,12 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
baseimage: ['debian:bullseye', 'ubuntu:20.04', 'ubuntu:22.04']
20+
baseimage: ['debian:bullseye', 'debian:trixie', 'ubuntu:20.04', 'ubuntu:24.04', 'fedora']
21+
go: [1.23, 1.24]
2122
steps:
2223
- uses: actions/checkout@v4
23-
- name: Pull base image - ${{ matrix.baseimage }}
24-
run: docker pull ${{ matrix.baseimage }}
25-
- name: Install packages for ${{ matrix.baseimage }}
26-
run: docker run --privileged --cidfile=/tmp/cidfile ${{ matrix.baseimage }} /bin/bash -e -c "export DEBIAN_FRONTEND=noninteractive; apt-get update; apt-get install -y sudo build-essential git golang dbus libsystemd-dev libpam-systemd systemd-container"
27-
- name: Persist base container
28-
run: |
29-
docker commit `cat /tmp/cidfile` go-systemd/container-tests
30-
docker rm -f `cat /tmp/cidfile`
31-
rm -f /tmp/cidfile
32-
- name: Run systemd from ${{ matrix.baseimage }}
33-
run: docker run --shm-size=2gb -d --cidfile=/tmp/cidfile --privileged -v ${PWD}:/src go-systemd/container-tests /bin/systemd --system
34-
- name: Fixup git
35-
run: docker exec --privileged `cat /tmp/cidfile` /bin/bash -e -c 'git config --global --add safe.directory /src'
36-
- name: Build tests
37-
run: docker exec --privileged `cat /tmp/cidfile` /bin/bash -e -c 'cd /src; ./scripts/ci-runner.sh build_tests'
38-
- name: Wait a bit for the whole system to settle
39-
run: sleep 30s
40-
- name: Run tests
41-
run: docker exec --privileged `cat /tmp/cidfile` /bin/bash -e -c 'cd /src; ./scripts/ci-runner.sh run_tests'
42-
- name: Cleanup
43-
run: docker kill `cat /tmp/cidfile`
24+
- name: Run tests in container
25+
run: ./scripts/ci-runner.sh run_in_ct ${{ matrix.baseimage }} ${{ matrix.go }}
4426

4527
all-done:
4628
needs:

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
17-
go: ['1.12.x', '1.23.x', '1.24.x']
17+
go: ['1.23.x', '1.24.x']
1818
steps:
1919
- run: sudo apt-get -qq update
2020
- name: Install libsystemd-dev

fixtures/oneshot.service

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[Unit]
2-
Description=start stop test
2+
Description=list jobs test
33

44
[Service]
5-
ExecStart=/bin/sh sleep 400
6-
ExecStopPost=/bin/sh sleep 1000
75
Type=oneshot
6+
ExecStart=/bin/sleep 30

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module github.com/coreos/go-systemd/v22
22

3-
go 1.12
3+
go 1.23
44

55
require github.com/godbus/dbus/v5 v5.1.0

login1/dbus_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestListSessions(t *testing.T) {
5353
t.Fatalf("expected uid '%d' but got '%s'", s.UID, lookup.Uid)
5454
}
5555

56-
validPath := regexp.MustCompile(`/org/freedesktop/login1/session/_[0-9]+`)
56+
validPath := regexp.MustCompile(`/org/freedesktop/login1/session/[_c][0-9]+`)
5757
if !validPath.MatchString(fmt.Sprint(s.Path)) {
5858
t.Fatalf("invalid session path: %s", s.Path)
5959
}

scripts/ci-runner.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,55 @@ function build_tests {
2323
go build -o ./test_bins/journal ./examples/journal/
2424
}
2525

26+
function run_in_ct {
27+
local image=$1
28+
local gover=$2
29+
local name="go-systemd/container-tests"
30+
local cidfile=/tmp/cidfile.$$
31+
local cid
32+
33+
# Figure out Go URL, based on $gover.
34+
local prefix="https://go.dev/dl/" filename
35+
filename=$(curl -fsSL "${prefix}?mode=json&include=all" |
36+
jq -r --arg Ver "go$gover" '. | map(select(.version | contains($Ver))) | first | .files[] | select(.os == "linux" and .arch == "amd64" and .kind == "archive") | .filename')
37+
gourl="${prefix}${filename}"
38+
39+
set -x
40+
docker pull "$image"
41+
docker run -i --privileged --cidfile="$cidfile" "$image" /bin/bash -e -x << EOF
42+
if dpkg --version; then
43+
export DEBIAN_FRONTEND=noninteractive
44+
apt-get -qq update
45+
apt-get -qq install -y -o Dpkg::Use-Pty=0 \
46+
sudo build-essential curl git dbus libsystemd-dev libpam-systemd systemd-container
47+
else # Assuming Fedora
48+
dnf install -qy sudo curl gcc git dbus systemd-devel systemd-container
49+
fi
50+
# Fixup git.
51+
git config --global --add safe.directory /src
52+
# Install Go.
53+
curl -fsSL "$gourl" | tar Cxz /usr/local
54+
ln -s /usr/local/go/bin/go /usr/local/bin/go
55+
go version
56+
go env
57+
EOF
58+
cid=$(cat "$cidfile")
59+
rm -f "$cidfile"
60+
docker commit "$cid" "$name"
61+
docker rm -f "$cid"
62+
63+
echo "Starting a container with systemd..."
64+
docker run --shm-size=2gb -d --cidfile="$cidfile" --privileged -v "${PWD}:/src" "$name" /sbin/init --system
65+
cid=$(cat "$cidfile")
66+
rm -f "$cidfile"
67+
docker exec --privileged "$cid" /bin/bash -e -c 'cd /src; ./scripts/ci-runner.sh build_tests'
68+
# Wait a bit for the whole system to settle.
69+
sleep 10s
70+
docker exec --privileged "$cid" /bin/bash -e -c 'cd /src; ./scripts/ci-runner.sh run_tests'
71+
# Cleanup.
72+
docker kill "$cid"
73+
}
74+
2675
function run_tests {
2776
pushd test_bins
2877
sudo -v
@@ -80,6 +129,11 @@ case "$subcommand" in
80129
build_tests
81130
;;
82131

132+
"run_in_ct" )
133+
shift
134+
run_in_ct "$@"
135+
;;
136+
83137
"run_tests" )
84138
echo "Running tests..."
85139
run_tests

sdjournal/journal_test.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,12 +453,29 @@ func TestJournalGetCatalog(t *testing.T) {
453453
t.Fatalf("Error adding matches to journal: %s", err)
454454
}
455455

456-
if err = waitAndNext(j); err != nil {
457-
t.Fatalf(err.Error())
456+
// Look for an entry with MESSAGE_ID (required for GetCatalog).
457+
found := false
458+
for range 100 {
459+
n, err := j.Next()
460+
if err != nil {
461+
t.Fatalf("Error reading journal: %s", err)
462+
}
463+
if n == 0 {
464+
break
465+
}
466+
467+
// Check if this entry has a MESSAGE_ID
468+
if _, err := j.GetData("MESSAGE_ID"); err == nil {
469+
found = true
470+
break
471+
}
458472
}
459473

460-
catalog, err := j.GetCatalog()
474+
if !found {
475+
t.Skip("No journal entries with MESSAGE_ID found for systemd-journald.service")
476+
}
461477

478+
catalog, err := j.GetCatalog()
462479
if err != nil {
463480
t.Fatalf("Failed to retrieve catalog entry: %s", err)
464481
}
@@ -488,7 +505,7 @@ func TestJournalGetBootID(t *testing.T) {
488505
t.Fatalf("Get bootID: %s is Null", bootID)
489506
}
490507

491-
fmt.Printf("Test GetBootID: %s", bootID)
508+
t.Log("bootid:", bootID)
492509
}
493510

494511
func contains(s []string, v string) bool {

0 commit comments

Comments
 (0)