Skip to content

Commit

Permalink
Merge pull request #397 from fabriziosestito/test/integration-tests
Browse files Browse the repository at this point in the history
test: add integration tests
  • Loading branch information
flavio authored Dec 14, 2023
2 parents b1ac8af + 6fabaf0 commit 29cb050
Show file tree
Hide file tree
Showing 25 changed files with 736 additions and 5 deletions.
19 changes: 17 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
command: check

test:
name: Test Suite
name: Unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@1e31de5234b9f8995739874a8ce0492dc87873e2 # v4.0.0
Expand All @@ -36,7 +36,22 @@ jobs:
- uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505 # v1.0.3
with:
command: test
args: --workspace
args: --workspace --lib

integration-test:
name: Integration tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@1e31de5234b9f8995739874a8ce0492dc87873e2 # v4.0.0
- uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1.0.7
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505 # v1.0.3
with:
command: test
args: --test '*'

fmt:
name: Rustfmt
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,4 @@ k8s-openapi = { version = "0.20.0", default-features = false, features = [
] }
rstest = "0.18"
test-context = "0.1"
tempfile = "3.8.1"
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ check:
test: fmt lint
cargo test --workspace

.PHONY: unit-tests
unit-test: fmt lint
cargo test --workspace --lib

.PHONY: integration-test
integration-tests: fmt lint
cargo test --test '*'

.PHONY: clean
clean:
cargo clean
2 changes: 1 addition & 1 deletion src/policy_evaluator/policy_evaluator_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ mod tests {
#[test]
fn build_policy_evaluator_pre() {
let engine = wasmtime::Engine::default();
let wat = include_bytes!("../../test_data/endless_wasm/wapc_endless_loop.wat");
let wat = include_bytes!("../../tests/data/endless_wasm/wapc_endless_loop.wat");
let module = wasmtime::Module::new(&engine, wat).expect("cannot compile WAT to wasm");

let policy_evaluator_builder = PolicyEvaluatorBuilder::new()
Expand Down
2 changes: 1 addition & 1 deletion src/runtimes/rego/context_aware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub(crate) mod tests {
namespace: Option<&str>,
name: &str,
) -> Result<kube::core::DynamicObject> {
let path = Path::new("test_data/fixtures/kube_context")
let path = Path::new("tests/data/fixtures/kube_context")
.join(resource_type)
.join(namespace.unwrap_or_default())
.join(format!("{name}.json"));
Expand Down
2 changes: 1 addition & 1 deletion src/runtimes/wapc/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ mod tests {
engine_conf.epoch_interruption(true);
let engine = wasmtime::Engine::new(&engine_conf).expect("cannot create wasmtime engine");

let wat = include_bytes!("../../../test_data/endless_wasm/wapc_endless_loop.wat");
let wat = include_bytes!("../../../tests/data/endless_wasm/wapc_endless_loop.wat");
let module = wasmtime::Module::new(&engine, wat).expect("cannot compile WAT to wasm");

// Create the wapc engine, the code will be interrupted after 10 ticks
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
174 changes: 174 additions & 0 deletions tests/data/pod_creation_flux_cat.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
{
"uid": "1299d386-525b-4032-98ae-1949f69f9cfc",
"kind": {
"group": "",
"version": "v1",
"kind": "Pod"
},
"resource": {
"group": "",
"version": "v1",
"resource": "pods"
},
"requestKind": {
"group": "",
"version": "v1",
"kind": "Pod"
},
"requestResource": {
"group": "",
"version": "v1",
"resource": "pods"
},
"name": "nginx",
"namespace": "default",
"operation": "CREATE",
"userInfo": {
"username": "kubernetes-admin",
"groups": ["system:masters", "system:authenticated"]
},
"object": {
"kind": "Pod",
"apiVersion": "v1",
"metadata": {
"name": "nginx",
"namespace": "default",
"uid": "04dc7a5e-e1f1-4e34-8d65-2c9337a43e64",
"creationTimestamp": "2020-11-12T15:18:36Z",
"labels": {
"env": "test"
},
"annotations": {
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Pod\",\"metadata\":{\"annotations\":{},\"labels\":{\"env\":\"test\"},\"name\":\"nginx\",\"namespace\":\"default\"},\"spec\":{\"containers\":[{\"image\":\"nginx\",\"imagePullPolicy\":\"IfNotPresent\",\"name\":\"nginx\"}],\"tolerations\":[{\"effect\":\"NoSchedule\",\"key\":\"example-key\",\"operator\":\"Exists\"}]}}\n",
"fluxcd.io/cat": "felix"
},
"managedFields": [
{
"manager": "kubectl",
"operation": "Update",
"apiVersion": "v1",
"time": "2020-11-12T15:18:36Z",
"fieldsType": "FieldsV1",
"fieldsV1": {
"f:metadata": {
"f:annotations": {
".": {},
"f:kubectl.kubernetes.io/last-applied-configuration": {}
},
"f:labels": {
".": {},
"f:env": {}
}
},
"f:spec": {
"f:containers": {
"k:{\"name\":\"nginx\"}": {
".": {},
"f:image": {},
"f:imagePullPolicy": {},
"f:name": {},
"f:resources": {},
"f:terminationMessagePath": {},
"f:terminationMessagePolicy": {}
}
},
"f:dnsPolicy": {},
"f:enableServiceLinks": {},
"f:restartPolicy": {},
"f:schedulerName": {},
"f:securityContext": {},
"f:terminationGracePeriodSeconds": {},
"f:tolerations": {}
}
}
}
]
},
"spec": {
"volumes": [
{
"name": "default-token-pvpz7",
"secret": {
"secretName": "default-token-pvpz7"
}
}
],
"containers": [
{
"name": "sleeping-sidecar",
"image": "alpine",
"command": ["sleep", "1h"],
"resources": {},
"volumeMounts": [
{
"name": "default-token-pvpz7",
"readOnly": true,
"mountPath": "/var/run/secrets/kubernetes.io/serviceaccount"
}
],
"terminationMessagePath": "/dev/termination-log",
"terminationMessagePolicy": "File",
"imagePullPolicy": "IfNotPresent"
},
{
"name": "nginx",
"image": "nginx",
"resources": {},
"volumeMounts": [
{
"name": "default-token-pvpz7",
"readOnly": true,
"mountPath": "/var/run/secrets/kubernetes.io/serviceaccount"
}
],
"securityContext": {
"privileged": true
},
"terminationMessagePath": "/dev/termination-log",
"terminationMessagePolicy": "File",
"imagePullPolicy": "IfNotPresent"
}
],
"restartPolicy": "Always",
"terminationGracePeriodSeconds": 30,
"dnsPolicy": "ClusterFirst",
"serviceAccountName": "default",
"serviceAccount": "default",
"securityContext": {},
"schedulerName": "default-scheduler",
"tolerations": [
{
"key": "node.kubernetes.io/not-ready",
"operator": "Exists",
"effect": "NoExecute",
"tolerationSeconds": 300
},
{
"key": "node.kubernetes.io/unreachable",
"operator": "Exists",
"effect": "NoExecute",
"tolerationSeconds": 300
},
{
"key": "dedicated",
"operator": "Equal",
"value": "tenantA",
"effect": "NoSchedule"
}
],
"priority": 0,
"enableServiceLinks": true,
"preemptionPolicy": "PreemptLowerPriority"
},
"status": {
"phase": "Pending",
"qosClass": "BestEffort"
}
},
"oldObject": null,
"dryRun": false,
"options": {
"kind": "CreateOptions",
"apiVersion": "meta.k8s.io/v1"
}
}
Loading

0 comments on commit 29cb050

Please sign in to comment.