Skip to content

Commit 5e9e9d1

Browse files
committed
Add integration workflow
1 parent 2020a3c commit 5e9e9d1

5 files changed

Lines changed: 272 additions & 3 deletions

File tree

.github/workflows/test.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Rust CI
2+
3+
on:
4+
push:
5+
branches: [ "main", "master" ]
6+
pull_request:
7+
branches: [ "main", "master" ]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
test:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Set up Homebrew
19+
run: |
20+
echo "/home/linuxbrew/.linuxbrew/bin" >> $GITHUB_PATH
21+
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
22+
23+
- name: Install Toolchain
24+
uses: dtolnay/rust-toolchain@stable
25+
26+
- name: Install Aeron Cache Backend
27+
run: |
28+
brew tap bhf/aeron-cache
29+
brew install aeron-cache
30+
31+
- name: Start Aeron Cache Backend
32+
run: |
33+
aeron-cache &
34+
# Wait for the environment file to be generated in ~/.aeron-cache/
35+
ENV_FILE="$HOME/.aeron-cache/aeron-cache-ui.env"
36+
37+
if [ -f "$ENV_FILE" ]; then
38+
echo "Environment file found"
39+
break
40+
fi
41+
echo "Waiting for $ENV_FILE..."
42+
sleep 1
43+
done
44+
45+
# Extract the API URL
46+
if [ -f "$ENV_FILE" ]; then
47+
API_URL=$(grep AERON_CACHE_API "$ENV_FILE" | cut -d'=' -f2)
48+
echo "Found API URL: $API_URL"
49+
echo "AERON_CACHE_API_URL=$API_URL" >> $GITHUB_ENV
50+
else
51+
echo "Error: $ENV_FILE not found after timeout"
52+
exit 1
53+
fi
54+
55+
- name: Run Tests
56+
run: cargo test
57+

Cargo.lock

Lines changed: 147 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ reqwest = { version = "0.11", features = ["blocking", "json"] }
1010
serde = { version = "1.0.228", features = ["derive"] }
1111
serde_json = "1.0.148"
1212

13+
[dev-dependencies]
14+
assert_cmd = "2.0"
15+
predicates = "3.1"

src/main.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ enum Commands {
6565
Delete {
6666
#[arg(help = "Name of the cache to delete")]
6767
name: String,
68+
#[arg(short, long, help = "Automatically confirm deletion")]
69+
yes: bool,
6870
},
6971
}
7072

@@ -94,8 +96,8 @@ fn main() -> Result<(), Box<dyn Error>> {
9496
Commands::Remove { name: cache_name, key } => {
9597
process_remove_item(rest_client, &aeron_cache_api_url, &cache_name, &key)?;
9698
}
97-
Commands::Delete { name } => {
98-
if Confirm::new()
99+
Commands::Delete { name, yes } => {
100+
if yes || Confirm::new()
99101
.with_prompt(format!(
100102
"Are you sure you want to delete cache '{}'? This action cannot be undone.",
101103
name
@@ -110,4 +112,3 @@ fn main() -> Result<(), Box<dyn Error>> {
110112
}
111113
Ok(())
112114
}
113-

tests/integration_test.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
use assert_cmd::Command;
2+
use predicates::prelude::*;
3+
use std::env;
4+
5+
fn get_api_url() -> String {
6+
env::var("AERON_CACHE_API_URL").unwrap_or_else(|_| "http://localhost:7070/api/v1/cache".to_string())
7+
}
8+
9+
#[test]
10+
fn test_help() -> Result<(), Box<dyn std::error::Error>> {
11+
let mut cmd = Command::cargo_bin("CacheCLI")?;
12+
cmd.arg("--help");
13+
cmd.assert()
14+
.success()
15+
.stdout(predicate::str::contains("A CLI for interacting with Aeron Cache"));
16+
Ok(())
17+
}
18+
19+
#[test]
20+
fn test_cache_lifecycle() -> Result<(), Box<dyn std::error::Error>> {
21+
let api_url = get_api_url();
22+
let cache_name = "test-cache-lifecycle";
23+
24+
// 1. Create Cache
25+
let mut cmd = Command::cargo_bin("CacheCLI")?;
26+
cmd.args(&["--api-url", &api_url, "create", cache_name]);
27+
cmd.assert()
28+
.success()
29+
.stdout(predicate::str::contains(format!("Created cache with id: {}", cache_name)));
30+
31+
// 2. Insert Item
32+
let mut cmd = Command::cargo_bin("CacheCLI")?;
33+
cmd.args(&["--api-url", &api_url, "insert", cache_name, "mykey", "myvalue"]);
34+
cmd.assert()
35+
.success()
36+
.stdout(predicate::str::contains(format!("Put item into cache with id: {}", cache_name)));
37+
38+
// 3. Get Item
39+
let mut cmd = Command::cargo_bin("CacheCLI")?;
40+
cmd.args(&["--api-url", &api_url, "get", cache_name, "mykey"]);
41+
cmd.assert()
42+
.success()
43+
.stdout(predicate::str::contains(format!("Got item from cache {} on key mykey with value myvalue", cache_name)));
44+
45+
// 4. Remove Item
46+
let mut cmd = Command::cargo_bin("CacheCLI")?;
47+
cmd.args(&["--api-url", &api_url, "remove", cache_name, "mykey"]);
48+
cmd.assert()
49+
.success()
50+
.stdout(predicate::str::contains(format!("Removed item from cache {} on key mykey", cache_name)));
51+
52+
// 5. Delete Cache (using the --yes flag)
53+
let mut cmd = Command::cargo_bin("CacheCLI")?;
54+
cmd.args(&["--api-url", &api_url, "delete", cache_name, "--yes"]);
55+
cmd.assert()
56+
.success()
57+
.stdout(predicate::str::contains(format!("Deleted cache: {}", cache_name)));
58+
59+
Ok(())
60+
}
61+

0 commit comments

Comments
 (0)