Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 4 additions & 22 deletions .github/workflows/containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,12 @@ jobs:
strategy:
fail-fast: false
matrix:
baseimage: ['debian:bullseye', 'ubuntu:20.04', 'ubuntu:22.04']
baseimage: ['debian:bullseye', 'debian:trixie', 'ubuntu:20.04', 'ubuntu:24.04', 'fedora']
go: [1.23, 1.24]
steps:
- uses: actions/checkout@v4
- name: Pull base image - ${{ matrix.baseimage }}
run: docker pull ${{ matrix.baseimage }}
- name: Install packages for ${{ matrix.baseimage }}
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"
- name: Persist base container
run: |
docker commit `cat /tmp/cidfile` go-systemd/container-tests
docker rm -f `cat /tmp/cidfile`
rm -f /tmp/cidfile
- name: Run systemd from ${{ matrix.baseimage }}
run: docker run --shm-size=2gb -d --cidfile=/tmp/cidfile --privileged -v ${PWD}:/src go-systemd/container-tests /bin/systemd --system
- name: Fixup git
run: docker exec --privileged `cat /tmp/cidfile` /bin/bash -e -c 'git config --global --add safe.directory /src'
- name: Build tests
run: docker exec --privileged `cat /tmp/cidfile` /bin/bash -e -c 'cd /src; ./scripts/ci-runner.sh build_tests'
- name: Wait a bit for the whole system to settle
run: sleep 30s
- name: Run tests
run: docker exec --privileged `cat /tmp/cidfile` /bin/bash -e -c 'cd /src; ./scripts/ci-runner.sh run_tests'
- name: Cleanup
run: docker kill `cat /tmp/cidfile`
- name: Run tests in container
run: ./scripts/ci-runner.sh run_in_ct ${{ matrix.baseimage }} ${{ matrix.go }}

all-done:
needs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: ['1.12.x', '1.23.x', '1.24.x']
go: ['1.23.x', '1.24.x']
steps:
- run: sudo apt-get -qq update
- name: Install libsystemd-dev
Expand Down
5 changes: 2 additions & 3 deletions fixtures/oneshot.service
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[Unit]
Description=start stop test
Description=list jobs test

[Service]
ExecStart=/bin/sh sleep 400
ExecStopPost=/bin/sh sleep 1000
Type=oneshot
ExecStart=/bin/sleep 30
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/coreos/go-systemd/v22

go 1.12
go 1.23

require github.com/godbus/dbus/v5 v5.1.0
2 changes: 1 addition & 1 deletion login1/dbus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestListSessions(t *testing.T) {
t.Fatalf("expected uid '%d' but got '%s'", s.UID, lookup.Uid)
}

validPath := regexp.MustCompile(`/org/freedesktop/login1/session/_[0-9]+`)
validPath := regexp.MustCompile(`/org/freedesktop/login1/session/[_c][0-9]+`)
if !validPath.MatchString(fmt.Sprint(s.Path)) {
t.Fatalf("invalid session path: %s", s.Path)
}
Expand Down
54 changes: 54 additions & 0 deletions scripts/ci-runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,55 @@ function build_tests {
go build -o ./test_bins/journal ./examples/journal/
}

function run_in_ct {
local image=$1
local gover=$2
local name="go-systemd/container-tests"
local cidfile=/tmp/cidfile.$$
local cid

# Figure out Go URL, based on $gover.
local prefix="https://go.dev/dl/" filename
filename=$(curl -fsSL "${prefix}?mode=json&include=all" |
jq -r --arg Ver "go$gover" '. | map(select(.version | contains($Ver))) | first | .files[] | select(.os == "linux" and .arch == "amd64" and .kind == "archive") | .filename')
gourl="${prefix}${filename}"

set -x
docker pull "$image"
docker run -i --privileged --cidfile="$cidfile" "$image" /bin/bash -e -x << EOF
if dpkg --version; then
export DEBIAN_FRONTEND=noninteractive
apt-get -qq update
apt-get -qq install -y -o Dpkg::Use-Pty=0 \
sudo build-essential curl git dbus libsystemd-dev libpam-systemd systemd-container
else # Assuming Fedora
dnf install -qy sudo curl gcc git dbus systemd-devel systemd-container
fi
# Fixup git.
git config --global --add safe.directory /src
# Install Go.
curl -fsSL "$gourl" | tar Cxz /usr/local
ln -s /usr/local/go/bin/go /usr/local/bin/go
go version
go env
EOF
cid=$(cat "$cidfile")
rm -f "$cidfile"
docker commit "$cid" "$name"
docker rm -f "$cid"

echo "Starting a container with systemd..."
docker run --shm-size=2gb -d --cidfile="$cidfile" --privileged -v "${PWD}:/src" "$name" /sbin/init --system
cid=$(cat "$cidfile")
rm -f "$cidfile"
docker exec --privileged "$cid" /bin/bash -e -c 'cd /src; ./scripts/ci-runner.sh build_tests'
# Wait a bit for the whole system to settle.
sleep 10s
docker exec --privileged "$cid" /bin/bash -e -c 'cd /src; ./scripts/ci-runner.sh run_tests'
# Cleanup.
docker kill "$cid"
}

function run_tests {
pushd test_bins
sudo -v
Expand Down Expand Up @@ -80,6 +129,11 @@ case "$subcommand" in
build_tests
;;

"run_in_ct" )
shift
run_in_ct "$@"
;;

"run_tests" )
echo "Running tests..."
run_tests
Expand Down
25 changes: 21 additions & 4 deletions sdjournal/journal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,12 +453,29 @@ func TestJournalGetCatalog(t *testing.T) {
t.Fatalf("Error adding matches to journal: %s", err)
}

if err = waitAndNext(j); err != nil {
t.Fatalf(err.Error())
// Look for an entry with MESSAGE_ID (required for GetCatalog).
found := false
for range 100 {
n, err := j.Next()
if err != nil {
t.Fatalf("Error reading journal: %s", err)
}
if n == 0 {
break
}

// Check if this entry has a MESSAGE_ID
if _, err := j.GetData("MESSAGE_ID"); err == nil {
found = true
break
}
}

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

catalog, err := j.GetCatalog()
if err != nil {
t.Fatalf("Failed to retrieve catalog entry: %s", err)
}
Expand Down Expand Up @@ -488,7 +505,7 @@ func TestJournalGetBootID(t *testing.T) {
t.Fatalf("Get bootID: %s is Null", bootID)
}

fmt.Printf("Test GetBootID: %s", bootID)
t.Log("bootid:", bootID)
}

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