-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add context-aware integration tests
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
- Loading branch information
1 parent
29cb050
commit 443bd1d
Showing
6 changed files
with
468 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use tempfile::TempDir; | ||
|
||
use policy_evaluator::{ | ||
evaluation_context::EvaluationContext, policy_evaluator::PolicyEvaluator, | ||
policy_evaluator::PolicyExecutionMode, policy_evaluator_builder::PolicyEvaluatorBuilder, | ||
}; | ||
use policy_fetcher::{policy::Policy, PullDestination}; | ||
|
||
pub(crate) async fn fetch_policy(policy_uri: &str, tempdir: TempDir) -> Policy { | ||
policy_evaluator::policy_fetcher::fetch_policy( | ||
policy_uri, | ||
PullDestination::LocalFile(tempdir.into_path()), | ||
None, | ||
) | ||
.await | ||
.expect("cannot fetch policy") | ||
} | ||
|
||
pub(crate) fn build_policy_evaluator( | ||
execution_mode: PolicyExecutionMode, | ||
policy: &Policy, | ||
eval_ctx: &EvaluationContext, | ||
) -> PolicyEvaluator { | ||
let policy_evaluator_builder = PolicyEvaluatorBuilder::new() | ||
.execution_mode(execution_mode) | ||
.policy_file(&policy.local_path) | ||
.expect("cannot read policy file") | ||
.enable_wasmtime_cache() | ||
.enable_epoch_interruptions(1, 2); | ||
|
||
let policy_evaluator_pre = policy_evaluator_builder | ||
.build_pre() | ||
.expect("cannot build policy evaluator pre"); | ||
|
||
policy_evaluator_pre | ||
.rehydrate(eval_ctx) | ||
.expect("cannot rehydrate policy evaluator") | ||
} | ||
|
||
pub(crate) fn load_request_data(request_file_name: &str) -> Vec<u8> { | ||
let request_file_path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
.join("tests/data") | ||
.join(request_file_name); | ||
std::fs::read(request_file_path).expect("cannot read request file") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
{ | ||
"kind": { | ||
"group": "apps", | ||
"kind": "Deployment", | ||
"version": "v1" | ||
}, | ||
"name": "api", | ||
"namespace": "customer-1", | ||
"object": { | ||
"apiVersion": "apps/v1", | ||
"kind": "Deployment", | ||
"metadata": { | ||
"annotations": { | ||
"deployment.kubernetes.io/revision": "1", | ||
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"apps/v1\",\"kind\":\"Deployment\",\"metadata\":{\"annotations\":{},\"labels\":{\"app\":\"api\",\"app.kubernetes.io/component\":\"api\"},\"name\":\"api\",\"namespace\":\"customer-1\"},\"spec\":{\"replicas\":3,\"selector\":{\"matchLabels\":{\"app\":\"api\"}},\"template\":{\"metadata\":{\"labels\":{\"app\":\"api\",\"app.kubernetes.io/component\":\"api\"}},\"spec\":{\"containers\":[{\"image\":\"api:1.0.0\",\"name\":\"api\",\"ports\":[{\"containerPort\":8080}]}]}}}}\n" | ||
}, | ||
"creationTimestamp": "2023-12-17T08:52:31Z", | ||
"generation": 1, | ||
"labels": { | ||
"app": "api", | ||
"app.kubernetes.io/component": "api", | ||
"customer-id": "1" | ||
}, | ||
"name": "api", | ||
"namespace": "customer-1", | ||
"resourceVersion": "1167496", | ||
"uid": "8a1e598b-cc4b-49b7-a465-bee6204c18db" | ||
}, | ||
"spec": { | ||
"progressDeadlineSeconds": 600, | ||
"replicas": 3, | ||
"revisionHistoryLimit": 10, | ||
"selector": { | ||
"matchLabels": { | ||
"app": "api" | ||
} | ||
}, | ||
"strategy": { | ||
"rollingUpdate": { | ||
"maxSurge": "25%", | ||
"maxUnavailable": "25%" | ||
}, | ||
"type": "RollingUpdate" | ||
}, | ||
"template": { | ||
"metadata": { | ||
"creationTimestamp": null, | ||
"labels": { | ||
"app": "api", | ||
"app.kubernetes.io/component": "api" | ||
} | ||
}, | ||
"spec": { | ||
"containers": [ | ||
{ | ||
"image": "api:1.0.0", | ||
"imagePullPolicy": "IfNotPresent", | ||
"name": "api", | ||
"ports": [ | ||
{ | ||
"containerPort": 8080, | ||
"protocol": "TCP" | ||
} | ||
], | ||
"resources": {}, | ||
"terminationMessagePath": "/dev/termination-log", | ||
"terminationMessagePolicy": "File" | ||
} | ||
], | ||
"dnsPolicy": "ClusterFirst", | ||
"restartPolicy": "Always", | ||
"schedulerName": "default-scheduler", | ||
"securityContext": {}, | ||
"terminationGracePeriodSeconds": 30 | ||
} | ||
} | ||
}, | ||
"status": { | ||
"conditions": [ | ||
{ | ||
"lastTransitionTime": "2023-12-17T08:52:32Z", | ||
"lastUpdateTime": "2023-12-17T08:52:32Z", | ||
"message": "Deployment does not have minimum availability.", | ||
"reason": "MinimumReplicasUnavailable", | ||
"status": "False", | ||
"type": "Available" | ||
}, | ||
{ | ||
"lastTransitionTime": "2023-12-17T08:52:31Z", | ||
"lastUpdateTime": "2023-12-17T08:52:32Z", | ||
"message": "ReplicaSet \"api-58f88975b6\" is progressing.", | ||
"reason": "ReplicaSetUpdated", | ||
"status": "True", | ||
"type": "Progressing" | ||
} | ||
], | ||
"observedGeneration": 1, | ||
"replicas": 3, | ||
"unavailableReplicas": 3, | ||
"updatedReplicas": 3 | ||
} | ||
}, | ||
|
||
"operation": "CREATE", | ||
"options": { | ||
"apiVersion": "meta.k8s.io/v1", | ||
"fieldManager": "kubectl-client-side-apply", | ||
"kind": "CreateOptions" | ||
}, | ||
"requestKind": { | ||
"group": "apps", | ||
"kind": "Deployment", | ||
"version": "v1" | ||
}, | ||
"requestResource": { | ||
"group": "apps", | ||
"resource": "deployments", | ||
"version": "v1" | ||
}, | ||
"resource": { | ||
"group": "apps", | ||
"resource": "deployments", | ||
"version": "v1" | ||
}, | ||
"uid": "8560a482-887d-49b2-8781-415d04a0dcb0", | ||
"userInfo": { | ||
"groups": ["system:masters", "system:authenticated"], | ||
"username": "system:admin" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.