Skip to content

Commit e64404b

Browse files
authored
modern rust pattern adoption (#5)
* modern rust pattern adoption * update w tests * update workflows
1 parent b8ab2a3 commit e64404b

7 files changed

Lines changed: 820 additions & 275 deletions

File tree

.github/workflows/ci.yml

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
name: Test Suite
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
- name: Install Rust toolchain
17+
uses: dtolnay/rust-toolchain@stable
18+
with:
19+
components: rustfmt
20+
- name: Install system dependencies
21+
run: |
22+
sudo apt-get update
23+
sudo apt-get install -y \
24+
dbus \
25+
dbus-x11 \
26+
python3 \
27+
python3-dbus \
28+
python3-gi \
29+
python3-gi-cairo \
30+
gir1.2-glib-2.0 \
31+
systemd \
32+
libdbus-1-dev \
33+
pkg-config
34+
- name: Cache cargo dependencies
35+
uses: actions/cache@v4
36+
with:
37+
path: |
38+
~/.cargo/registry
39+
~/.cargo/git
40+
target
41+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
42+
restore-keys: |
43+
${{ runner.os }}-cargo-
44+
- name: Check code formatting
45+
run: cargo fmt -- --check
46+
- name: Start D-Bus session for tests
47+
run: |
48+
# Start D-Bus daemon for testing
49+
export DBUS_SESSION_BUS_ADDRESS=$(dbus-daemon --session --print-address --fork)
50+
echo "DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS" >> $GITHUB_ENV
51+
# Give D-Bus time to start
52+
sleep 2
53+
# Verify D-Bus is working
54+
echo "Testing D-Bus connection..."
55+
dbus-send --session --dest=org.freedesktop.DBus --type=method_call \
56+
--print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames > /dev/null
57+
echo "D-Bus session ready"
58+
- name: Run unit tests
59+
env:
60+
RUST_BACKTRACE: 1
61+
run: |
62+
echo "Running all tests..."
63+
cargo test --verbose
64+
- name: Run integration tests with output
65+
env:
66+
RUST_BACKTRACE: 1
67+
run: |
68+
echo "Running integration tests with detailed output..."
69+
cargo test --test integration_tests -- --nocapture
70+
- name: Test mock script standalone
71+
run: |
72+
echo "Testing mock media player script..."
73+
timeout 3s python3 tests/mock_media_player.py || true
74+
echo "Mock script test completed"
75+
- name: Build release binary
76+
run: |
77+
echo "Building release version..."
78+
cargo build --release
79+
ls -la target/release/
80+
- name: Upload test artifacts on failure
81+
if: failure()
82+
uses: actions/upload-artifact@v4
83+
with:
84+
name: test-logs-${{ github.run_number }}
85+
path: |
86+
target/debug/deps/
87+
retention-days: 5
88+
89+
security:
90+
name: Security Audit
91+
runs-on: ubuntu-latest
92+
steps:
93+
- name: Checkout code
94+
uses: actions/checkout@v4
95+
- name: Install Rust toolchain
96+
uses: dtolnay/rust-toolchain@stable
97+
- name: Install cargo-audit
98+
run: cargo install cargo-audit
99+
- name: Run security audit
100+
run: cargo audit
101+
102+
coverage:
103+
name: Code Coverage
104+
runs-on: ubuntu-latest
105+
steps:
106+
- name: Checkout code
107+
uses: actions/checkout@v4
108+
- name: Install Rust toolchain
109+
uses: dtolnay/rust-toolchain@stable
110+
with:
111+
components: llvm-tools-preview
112+
- name: Install system dependencies
113+
run: |
114+
sudo apt-get update
115+
sudo apt-get install -y \
116+
dbus \
117+
dbus-x11 \
118+
python3-dbus \
119+
python3-gi \
120+
libdbus-1-dev \
121+
pkg-config
122+
- name: Install cargo-llvm-cov
123+
run: cargo install cargo-llvm-cov
124+
- name: Start D-Bus session for coverage
125+
run: |
126+
export DBUS_SESSION_BUS_ADDRESS=$(dbus-daemon --session --print-address --fork)
127+
echo "DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS" >> $GITHUB_ENV
128+
sleep 2
129+
- name: Generate code coverage
130+
run: |
131+
cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
132+
- name: Upload coverage to Codecov
133+
uses: codecov/codecov-action@v4
134+
with:
135+
files: lcov.info
136+
fail_ci_if_error: false
137+
token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/test.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Tests
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
7+
jobs:
8+
test:
9+
name: Run Tests
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
- name: Install Rust
15+
uses: dtolnay/rust-toolchain@stable
16+
with:
17+
components: rustfmt
18+
- name: Install D-Bus and Python dependencies
19+
run: |
20+
sudo apt-get update
21+
sudo apt-get install -y \
22+
dbus \
23+
dbus-x11 \
24+
python3 \
25+
python3-dbus \
26+
python3-gi \
27+
python3-gi-cairo \
28+
gir1.2-glib-2.0 \
29+
libdbus-1-dev \
30+
pkg-config
31+
- name: Setup D-Bus session
32+
run: |
33+
export DBUS_SESSION_BUS_ADDRESS=$(dbus-daemon --session --print-address --fork)
34+
echo "DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS" >> $GITHUB_ENV
35+
sleep 1
36+
dbus-send --session --dest=org.freedesktop.DBus --type=method_call \
37+
--print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames > /dev/null
38+
echo "✅ D-Bus session ready"
39+
- name: Cache dependencies
40+
uses: actions/cache@v4
41+
with:
42+
path: |
43+
~/.cargo/registry
44+
~/.cargo/git
45+
target
46+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
47+
restore-keys: |
48+
${{ runner.os }}-cargo-
49+
- name: Run tests
50+
env:
51+
RUST_BACKTRACE: 1
52+
run: |
53+
echo "🧪 Running all tests..."
54+
cargo test --verbose
55+
- name: Verify mock script works
56+
run: |
57+
echo "🎭 Testing mock media player script..."
58+
timeout 2s python3 tests/mock_media_player.py || echo "Mock script completed (expected timeout)"
59+
- name: Build release
60+
run: |
61+
echo "🔨 Building release binary..."
62+
cargo build --release
63+
echo "✅ Release build successful"

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ The main function of this project is to keep any sway based WM from going into a
1515
* `toml`: For creating config file
1616
* `serde`: To serialize toml
1717

18+
## Testing
19+
20+
Swaddle includes comprehensive tests including D-Bus integration tests with a mock media player.
21+
22+
### Prerequisites for Testing
23+
24+
You must install the `pyton-dbus and python-gobject` packages for the dbus mock testing to work as intended.
25+
26+
### Running Tests
27+
28+
```bash
29+
# Run all tests
30+
cargo test
31+
32+
# Run the mock media player standalone (for debugging)
33+
python3 tests/mock_media_player.py
34+
```
35+
1836
## Installation
1937

2038
Swaddle can be installed from the AUR:

0 commit comments

Comments
 (0)