Skip to content

Commit 0fba0e5

Browse files
authored
ci: add tests and lint for PRs (#2)
1 parent 7b951f2 commit 0fba0e5

File tree

7 files changed

+83
-19
lines changed

7 files changed

+83
-19
lines changed

.envrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ has nix && use flake . -L
22
watch_file *.nix
33
dotenv_if_exists .env # You can create a .env file with your env vars for this project. You can also use .secrets if you are using act. See the line below.
44
dotenv_if_exists .secrets # Used by [act](https://nektosact.com/) to load secrets into the pipelines
5+
strict_env
6+
7+
env_vars_required SECURE_API_URL SECURE_API_TOKEN
8+
59
export RUST_BACKTRACE=1
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: CI - Pull Request
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
8+
jobs:
9+
lint:
10+
name: Lint
11+
runs-on: ubuntu-latest
12+
defaults:
13+
run:
14+
shell: nix develop --command bash {0}
15+
steps:
16+
- name: Fetch code
17+
uses: actions/checkout@v4
18+
19+
- name: Install nix
20+
uses: DeterminateSystems/nix-installer-action@main
21+
22+
- name: Run lint
23+
run: |
24+
just lint
25+
26+
pre-commit:
27+
name: Pre-commit
28+
runs-on: ubuntu-latest
29+
defaults:
30+
run:
31+
shell: nix develop --command bash {0}
32+
steps:
33+
- name: Fetch code
34+
uses: actions/checkout@v4
35+
36+
- name: Install nix
37+
uses: DeterminateSystems/nix-installer-action@main
38+
39+
- name: Run pre-commit
40+
run: |
41+
pre-commit run -a
42+
43+
build-and-test:
44+
name: Build and test
45+
runs-on: ubuntu-latest
46+
defaults:
47+
run:
48+
shell: nix develop --command bash {0}
49+
steps:
50+
- name: Fetch code
51+
uses: actions/checkout@v4
52+
53+
- name: Install nix
54+
uses: DeterminateSystems/nix-installer-action@main
55+
56+
- name: Run tests
57+
run: |
58+
just test
59+
env:
60+
SECURE_API_URL: https://us2.app.sysdig.com
61+
SECURE_API_TOKEN: ${{ secrets.SECURE_API_TOKEN }}

.pre-commit-config.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,3 @@ repos:
1212
- id: trailing-whitespace
1313
- id: end-of-file-fixer
1414
- id: check-yaml
15-
16-
- repo: local
17-
hooks:
18-
- id: cargo-nextest
19-
name: cargo nextest
20-
entry: cargo nextest run
21-
language: system
22-
files: \.rs$
23-
pass_filenames: false

Justfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@ fix:
88
fmt:
99
cargo fmt
1010

11+
lint:
12+
cargo check
13+
cargo clippy
14+
1115
watch:
1216
cargo watch -x "nextest run"

flake.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
rust-analyzer
5252
lldb
5353
pre-commit
54-
sysdig-cli-scanner
5554
];
5655

5756
inputsFrom = [ sysdig-lsp ];

src/infra/sysdig_image_scanner.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,23 @@ impl ImageScanner for SysdigImageScanner {
175175
#[cfg(test)]
176176
#[serial_test::file_serial]
177177
mod tests {
178+
use lazy_static::lazy_static;
179+
178180
use crate::app::ImageScanner;
179181

180182
use super::{SysdigAPIToken, SysdigImageScanner};
181183

184+
lazy_static! {
185+
static ref SYSDIG_SECURE_URL: String =
186+
std::env::var("SECURE_API_URL").expect("SECURE_API_URL env var not set");
187+
static ref SYSDIG_SECURE_TOKEN: SysdigAPIToken =
188+
SysdigAPIToken(std::env::var("SECURE_API_TOKEN").expect("SECURE_API_TOKEN not set"));
189+
}
190+
182191
#[tokio::test]
183192
async fn it_retrieves_the_scanner_from_the_specified_version() {
184-
let sysdig_url = "https://us2.app.sysdig.com".to_string();
185-
let sysdig_secure_token = SysdigAPIToken(std::env::var("SECURE_API_TOKEN").unwrap());
186-
187-
let scanner = SysdigImageScanner::new(sysdig_url, sysdig_secure_token);
193+
let scanner =
194+
SysdigImageScanner::new(SYSDIG_SECURE_URL.clone(), SYSDIG_SECURE_TOKEN.clone());
188195

189196
let report = scanner.scan("ubuntu:22.04").await.unwrap();
190197

@@ -195,10 +202,8 @@ mod tests {
195202

196203
#[tokio::test]
197204
async fn it_scans_the_ubuntu_image_correctly() {
198-
let sysdig_url = "https://us2.app.sysdig.com".to_string();
199-
let sysdig_secure_token = SysdigAPIToken(std::env::var("SECURE_API_TOKEN").unwrap());
200-
201-
let scanner = SysdigImageScanner::new(sysdig_url, sysdig_secure_token);
205+
let scanner =
206+
SysdigImageScanner::new(SYSDIG_SECURE_URL.clone(), SYSDIG_SECURE_TOKEN.clone());
202207

203208
let report = scanner.scan_image("ubuntu:22.04").await.unwrap();
204209

tests/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl TestClient {
4141
.initialize(InitializeParams {
4242
initialization_options: Some(json!({"sysdig":
4343
{
44-
"api_url": "https://us2.app.sysdig.com"
44+
"api_url": "some_api_url"
4545
}
4646
})),
4747
..Default::default()

0 commit comments

Comments
 (0)