Skip to content

Commit 9fd5d38

Browse files
authored
Container tests (#5)
1 parent 5c72842 commit 9fd5d38

File tree

8 files changed

+176
-9
lines changed

8 files changed

+176
-9
lines changed

.github/workflows/testing-farm.yaml

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Run tests on Testing Farm
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [ master, container-tests ]
66
pull_request_target:
77
types: [opened, synchronize, reopened]
88

@@ -20,7 +20,7 @@ jobs:
2020
uses: actions/checkout@v4
2121

2222
- name: Test init on Fedora VM
23-
uses: sclorg/testing-farm-as-github-action@v4
23+
uses: sclorg/testing-farm-as-github-action@main
2424
with:
2525
api_key: ${{ secrets.TESTING_FARM_API_TOKEN }}
2626
compose: Fedora-Rawhide
@@ -42,7 +42,7 @@ jobs:
4242
uses: actions/checkout@v4
4343

4444
- name: Test upgrade on Fedora VM
45-
uses: sclorg/testing-farm-as-github-action@v4
45+
uses: sclorg/testing-farm-as-github-action@main
4646
with:
4747
api_key: ${{ secrets.TESTING_FARM_API_TOKEN }}
4848
compose: Fedora-Rawhide
@@ -51,4 +51,49 @@ jobs:
5151
pull_request_status_name: "Fedora upgrade test"
5252
update_pull_request_status: "true"
5353
create_github_summary: "true"
54+
container-test-init:
55+
runs-on: ubuntu-latest
56+
57+
permissions:
58+
contents: read
59+
pull-requests: write
60+
statuses: write
61+
62+
steps:
63+
- name: Checkout repository
64+
uses: actions/checkout@v4
65+
66+
- name: Test init on Fedora container
67+
uses: sclorg/testing-farm-as-github-action@main
68+
with:
69+
api_key: ${{ secrets.TESTING_FARM_API_TOKEN }}
70+
compose: null
71+
tmt_path: "tmt"
72+
tmt_plan_regex: "container-fedora-init"
73+
pull_request_status_name: "Fedora container init test"
74+
update_pull_request_status: "true"
75+
create_github_summary: "true"
76+
container-test-upgrade:
77+
runs-on: ubuntu-latest
78+
79+
permissions:
80+
contents: read
81+
pull-requests: write
82+
statuses: write
83+
84+
steps:
85+
- name: Checkout repository
86+
uses: actions/checkout@v4
87+
88+
- name: Test upgrade on Fedora container
89+
uses: sclorg/testing-farm-as-github-action@main
90+
with:
91+
api_key: ${{ secrets.TESTING_FARM_API_TOKEN }}
92+
compose: null
93+
tmt_path: "tmt"
94+
tmt_plan_regex: "container-fedora-upgrade"
95+
pull_request_status_name: "Fedora container upgrade test"
96+
update_pull_request_status: "true"
97+
create_github_summary: "true"
98+
5499

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: /plans/fedora-init-container
2+
summary: Run init test in a fedora container environment
3+
provision:
4+
how: container
5+
image: fedora:latest
6+
discover:
7+
how: fmf
8+
filter: tag:container-init-fedora
9+
execute:
10+
how: tmt
11+
12+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: /plans/fedora-upgrade-container
2+
summary: Run upgrade test in a fedora container environment
3+
provision:
4+
how: container
5+
image: fedora
6+
discover:
7+
how: fmf
8+
filter: tag:fedora-upgrade-container
9+
execute:
10+
how: tmt
11+
12+

tmt/plans/fedora-init.fmf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: /plans/fedora
1+
name: /plans/fedora-init
22
summary: Run tests in a fedora virtual machine environment
33
discover:
44
how: fmf

tmt/tests/container/sanity/init/init.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ cd repo
55
git fetch origin "$TESTING_FARM_GIT_REF"
66
git checkout FETCH_HEAD
77

8+
grep -q systemd /proc/1/comm
9+
echo "Return value CONTAINER: $?"
10+
811
# setup
912
autoreconf -vfi
1013
./configure --prefix=/usr
@@ -13,10 +16,11 @@ make
1316
# initialization
1417
./bin/postgresql-setup --init
1518

16-
# start postgresql
19+
# start postgresql and check if it's running
1720
PGDATA=/var/lib/pgsql/data
1821
LOGFILE=/var/lib/pgsql/logfile
22+
su - postgres -c "
1923
/usr/bin/pg_ctl -D $PGDATA -l $LOGFILE start
24+
pg_ctl -D $PGDATA status && echo \"PostgreSQL is running\" || { echo \"PostgreSQL is NOT running\"; exit 1; }
25+
"
2026

21-
# check if it is running
22-
pg_ctl -D $PGDATA status && echo "PostgreSQL is running" || { echo "PostgreSQL is NOT running"; exit 1; }

tmt/tests/container/sanity/init/main.fmf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
summary: Check whether the machine is a container
1+
summary: Postgresql-setup init test in a fedora rawhide container
22
require:
33
- make
44
- m4
@@ -11,7 +11,9 @@ require:
1111
- automake
1212
- autoconf-archive
1313
- git
14+
test: ./init.sh
1415
framework: shell
16+
duration: 10m
17+
tag: container-init-fedora
1518
16-
test: ./init.sh
1719

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
summary: Postgresql-setup upgrade test in a fedora rawhide container
2+
require:
3+
- make
4+
- m4
5+
- docbook-utils
6+
- help2man
7+
- elinks
8+
- postgresql-server
9+
- coreutils
10+
- autoconf
11+
- automake
12+
- autoconf-archive
13+
- git
14+
test: ./upgrade.sh
15+
framework: shell
16+
duration: 10m
17+
tag: fedora-upgrade-container
18+
19+
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/bash
2+
# prep
3+
git clone "$TESTING_FARM_GIT_URL" repo
4+
cd repo
5+
git fetch origin "$TESTING_FARM_GIT_REF"
6+
git checkout FETCH_HEAD
7+
8+
echo "Fedora release:"
9+
cat /etc/fedora-release
10+
11+
# install postgresql16
12+
dnf -y install postgresql16-server
13+
14+
# setup
15+
autoreconf -vfi
16+
./configure --prefix=/usr
17+
make
18+
19+
# initialization
20+
./bin/postgresql-setup --init
21+
22+
# start postgresql and check if it's running
23+
PGDATA=/var/lib/pgsql/data
24+
LOGFILE=/var/lib/pgsql/logfile
25+
su - postgres -c "
26+
/usr/bin/pg_ctl -D $PGDATA -l $LOGFILE start
27+
pg_ctl -D $PGDATA status && echo \"PostgreSQL is running\" || { echo \"PostgreSQL is NOT running\"; exit 1; }
28+
"
29+
30+
# insert data
31+
su - postgres -c "
32+
echo \"User switched\";
33+
34+
createdb testdb;
35+
psql -U postgres -d testdb -c \"create table users (id serial primary key, name text)\";
36+
psql -U postgres -d testdb -c \"insert into users (name) values ('Alice'), ('Bob'), ('Celine')\"
37+
"
38+
su - postgres -c '
39+
psql -U postgres -d testdb -c "select * from users"
40+
' > expected.txt
41+
42+
echo "Expected:"
43+
cat expected.txt
44+
45+
# uninstall postgresql
46+
dnf -y remove postgresql-server postgresql-private-libs postgresql libicu
47+
48+
# install postgresql17
49+
dnf -y install postgresql17-upgrade
50+
51+
# run --upgrade
52+
./bin/postgresql-setup --upgrade
53+
54+
# start postgresql and check if it's running
55+
su - postgres -c "
56+
/usr/bin/pg_ctl -D $PGDATA -l $LOGFILE start
57+
pg_ctl -D $PGDATA status && echo \"PostgreSQL is running\" || { echo \"PostgreSQL is NOT running\"; exit 1; }
58+
"
59+
60+
su - postgres -c '
61+
psql -U postgres -d testdb -c "select * from users"
62+
' > actual.txt
63+
64+
echo "Actual:"
65+
cat actual.txt
66+
67+
diff -q expected.txt actual.txt && echo "Actual and expected outputs match" || { echo "Actual and expected outputs differ"; exit 1; }
68+
69+
70+
71+
72+
73+

0 commit comments

Comments
 (0)