Skip to content

Commit

Permalink
add new test case
Browse files Browse the repository at this point in the history
  • Loading branch information
maheshrayas committed Apr 10, 2024
1 parent 791b831 commit 444e381
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
2 changes: 0 additions & 2 deletions tests/data/test-deploy1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ kind: Deployment
metadata:
namespace: kuber1
name: test-kuber1-deploy1
annotations:
kubesaver.com/ignore: "true"
labels:
app: go-app-kuber1
spec:
Expand Down
30 changes: 30 additions & 0 deletions tests/data/test-ignore-downscale-14.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: v1
kind: Namespace
metadata:
name: kuber14
---
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: kuber14
name: test-kuber14-deploy1
annotations:
kubesaver.com/ignore: "true"
labels:
app: go-app-kuber14
spec:
replicas: 2
selector:
matchLabels:
app: go-app
template:
metadata:
labels:
app: go-app
spec:
containers:
- name: go-app
image: maheshrayas/goapp:1.0
ports:
- containerPort: 8090
---
17 changes: 17 additions & 0 deletions tests/downscaler/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,20 @@ async fn test4_hpa_scale_all_resources_replicas_1() {
//Deployment must be scaled back to original replicas
assert_eq!(d.spec.unwrap().replicas, Some(3));
}

#[tokio::test]
async fn test5_check_if_ignored() {
let f = File::open("tests/rules/rules14.yaml").unwrap();
let r: Rules = serde_yaml::from_reader(f).unwrap();
let client = Client::try_default()
.await
.expect("Failed to read kubeconfig");
r.process_rules(client.clone(), None, None, SCALED_STATE.clone())
.await
.ok();
// kube-saver must ignore
let api: Api<Deployment> = Api::namespaced(client.clone(), "kuber14");
let d = api.get("test-kuber14-deploy1").await.unwrap();
assert_eq!(d.spec.unwrap().replicas, Some(0));

}
7 changes: 7 additions & 0 deletions tests/rules/rules14.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rules:
- id: rules-downscale-kuber14
uptime: Mon-Sun 22:59-23:00 Australia/Sydney
jmespath: "metadata.name == 'kuber14'"
resource:
- Namespace
replicas: 0

0 comments on commit 444e381

Please sign in to comment.