Skip to content

Commit

Permalink
Add windows support to golem tests. (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
hulto authored May 25, 2023
1 parent 995d1be commit 4790540
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 84 deletions.
76 changes: 4 additions & 72 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
run: go test -v -race -coverprofile='coverage.out' -covermode=atomic ./tavern/...
- name: 📶 Upload Coverage Results
uses: codecov/codecov-action@v3
imix:
implants:
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -55,80 +55,12 @@ jobs:
- name: rust-cache
uses: Swatinem/rust-cache@v2
with:
workspaces: "./implants/imix -> ../target"
workspaces: "./implants/ -> ../target"
- name: Install latest nextest release
uses: taiki-e/install-action@nextest
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: 🔎 Run tests
run: cd ./implants/imix && cargo llvm-cov nextest --lcov --output-path lcov.info
run: cd ./implants/ && cargo llvm-cov nextest --lcov --output-path lcov.info
- name: 📶 Upload Coverage Results
uses: codecov/codecov-action@v3

tavern-graphql-rust:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- macOS-latest
- windows-latest
steps:
- uses: actions/checkout@v3
- name: 👾 Disable defender
if: matrix.os == 'windows-latest'
run: start-process -filepath powershell -ArgumentList '/c','Set-MpPreference -DisableRealtimeMonitoring $true' -verb RunAs
shell: powershell
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2022-11-03
default: true
profile: minimal
- name: rust-cache
uses: Swatinem/rust-cache@v2
with:
workspaces: "./implants/pkg/tavern -> ../target"
- name: Install latest nextest release
uses: taiki-e/install-action@nextest
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: 🔎 Run tests
run: cd ./implants/pkg/tavern && cargo llvm-cov nextest --lcov --output-path lcov.info
- name: 📶 Upload Coverage Results
uses: codecov/codecov-action@v3

eldritch:
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
matrix:
os:
- ubuntu-latest
- macOS-latest
- windows-latest
steps:
- uses: actions/checkout@v3
- if: matrix.os == 'windows-latest'
run: start-process -filepath powershell -ArgumentList '/c','Set-MpPreference -DisableRealtimeMonitoring $true' -verb RunAs
name: 👾 Disable defender
shell: powershell
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2022-11-03
default: true
profile: minimal
- name: rust-cache
uses: Swatinem/rust-cache@v2
with:
workspaces: "./implants/eldritch -> ../target"
components: llvm-tools-preview
- name: Install latest nextest release
uses: taiki-e/install-action@nextest
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: 🔎 Run tests
run: cd ./implants/eldritch && cargo llvm-cov nextest --lcov --output-path lcov.info
- name: 📶 Upload Coverage Results
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v3
5 changes: 4 additions & 1 deletion implants/eldritch/src/assets/copy_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ mod tests {
let path_dst = String::from(tmp_file_dst.path().to_str().unwrap());

// Run our code
copy("exec_script/hello_word.sh".to_string(), path_dst)?;
#[cfg(any(target_os = "linux", target_os = "macos"))]
copy("exec_script/hello_world.sh".to_string(), path_dst)?;
#[cfg(any(target_os = "windows"))]
copy("exec_script/hello_world.bat".to_string(), path_dst)?;

// Read
let mut contents = String::new();
Expand Down
2 changes: 1 addition & 1 deletion implants/eldritch/src/assets/list_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mod tests {
fn test_assets_list() -> anyhow::Result<()>{
let res_all_embedded_files = list()?;

assert_eq!(res_all_embedded_files, ["exec_script/hello_word.sh", "exec_script/main.eld", "print/main.eld"]);
assert_eq!(res_all_embedded_files, [ "exec_script/hello_world.bat", "exec_script/hello_world.sh", "exec_script/main.eld", "print/main.eld"]);

Ok(())
}
Expand Down
13 changes: 7 additions & 6 deletions implants/golem/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ fn test_golem_main_file_not_found() -> anyhow::Result<()> {
let mut cmd = Command::cargo_bin("golem")?;

cmd.arg("nonexistentdir/run.tome");
#[cfg(target_os = "linux")]
cmd.assert()
.failure()
.stderr(predicate::str::contains("Error: No such file or directory"));
#[cfg(target_os = "windows")]
cmd.assert()
.failure()
.stderr(predicate::str::contains("Error: The system cannot find the path specified. (os error 3)"));

Ok(())
}
Expand Down Expand Up @@ -67,8 +72,7 @@ fn test_golem_main_basic_async() -> anyhow::Result<()> {
cmd.arg("../../tests/golem_cli_test/download_test.tome");
cmd.assert()
.success()
.stderr(predicate::str::contains(r#"OKAY!"#));

.stdout(predicate::str::contains(r#"OKAY!"#));
Ok(())
}

Expand Down Expand Up @@ -106,10 +110,7 @@ fn test_golem_main_embedded_files() -> anyhow::Result<()> {

cmd.assert()
.success()
.stderr(predicate::str::contains(r#"This script just prints"#));
cmd.assert()
.success()
.stderr(predicate::str::contains(r#"hello from an embedded shell script"#));
.stdout(predicate::str::contains(r#"This script just prints"#));

Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions tests/embedded_files_test/exec_script/hello_world.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo hello from an embedded shell script
14 changes: 12 additions & 2 deletions tests/embedded_files_test/exec_script/main.eld
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
assets.copy("exec_script/hello_word.sh","/tmp/abcd")
print(sys.shell("chmod +x /tmp/abcd && /tmp/abcd"))
def copy_script_and_execute():
if sys.is_linux() or sys.is_macos():
assets.copy("exec_script/hello_world.sh","/tmp/golem_cli_test-copy_script_and_execute")
shell_res = sys.shell("chmod +x /tmp/golem_cli_test-copy_script_and_execute && /tmp/golem_cli_test-copy_script_and_execute")
print(shell_res)
elif sys.is_windows():
assets.copy("exec_script/hello_world.bat","C:\Windows\Temp\golem_cli_test-copy_script_and_execute")
shell_res = sys.shell("C:\Windows\Temp\golem_cli_test-copy_script_and_execute")
print(shell_res)


copy_script_and_execute()
17 changes: 15 additions & 2 deletions tests/golem_cli_test/download_test.tome
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
file.download("https://github.com/KCarretto/realm/releases/download/v0.0.1/imix-linux-x64","abc")
print("OKAY!")
def download_stuff_test():
dest_path = "Fail"
if sys.is_linux() or sys.is_macos():
dest_path = "/tmp/golem_cli_test-download_test_dest"
elif sys.is_windows():
dest_path = "C:\Windows\Temp\golem_cli_test-download_test_dest"
else:
print("Failure - OS not supported")
return -1

file.download("https://github.com/KCarretto/realm/releases/download/v0.0.1/imix-linux-x64",dest_path)
print("OKAY!")
return 0

download_stuff_test()

0 comments on commit 4790540

Please sign in to comment.