Skip to content

Commit

Permalink
Add additional node in test inventory
Browse files Browse the repository at this point in the history
Add Rust and Python test cases for the new node
  • Loading branch information
simu committed Sep 11, 2023
1 parent 7036da9 commit 3a7e144
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,4 +629,40 @@ mod node_tests {

assert_eq!(params, expected);
}

#[test]
fn test_render_n3() {
let r = Reclass::new(
"./tests/inventory/nodes",
"./tests/inventory/classes",
false,
)
.unwrap();
let mut n = Node::parse(&r, "n3").unwrap();
n.render(&r).unwrap();
let params: Value = n.parameters.into();

let expected = r#"
cluster:
name: c-test-cluster-1234
openshift:
infraID: c-test-cluster-1234-xlk3f
clusterID: 2888efd2-8a1b-4846-82ec-3a99506e2c70
baseDomain: c-test-cluster-1234.example.org
appsDomain: apps.c-test-cluster-1234.example.org
apiURL: api.c-test-cluster-1234.example.org
ssh_key: ""
_reclass_:
environment: base
name:
short: n3
parts: ["n3"]
full: n3
path: n3
"#;
let mut expected: Value = Mapping::from_str(expected).unwrap().into();
expected.render(&Mapping::new()).unwrap();

assert_eq!(params, expected);
}
}
4 changes: 4 additions & 0 deletions tests/inventory/classes/cls3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
classes:
- cls4
- cls5
- cls6
3 changes: 3 additions & 0 deletions tests/inventory/classes/cls4.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
parameters:
cluster:
name: c-test-cluster-1234
6 changes: 6 additions & 0 deletions tests/inventory/classes/cls5.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
openshift:
baseDomain: ${cluster:name}.example.com
appsDomain: apps.${openshift:baseDomain}
apiURL: api.${openshift:baseDomain}
ssh_key: ""
6 changes: 6 additions & 0 deletions tests/inventory/classes/cls6.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
openshift:
infraID: c-test-cluster-1234-xlk3f
clusterID: 2888efd2-8a1b-4846-82ec-3a99506e2c70
baseDomain: c-test-cluster-1234.example.org
appsDomain: apps.${openshift:baseDomain}
2 changes: 2 additions & 0 deletions tests/inventory/nodes/n3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
classes:
- cls3
29 changes: 29 additions & 0 deletions tests/test_nodeinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,32 @@ def test_nodeinfo_n2():
"foo": {"foo": "nested.cls1", "bar": "n2"},
"bar": "bar",
}


def test_nodeinfo_n3():
r = reclass_rs.Reclass(
nodes_path="./tests/inventory/nodes", classes_path="./tests/inventory/classes"
)
n = r.nodeinfo("n3")
assert n.applications == []
assert n.classes == ["cls4", "cls5", "cls6", "cls3"]
assert n.parameters == {
"_reclass_": {
"environment": "base",
"name": {
"full": "n3",
"parts": ["n3"],
"path": "n3",
"short": "n3",
},
},
"cluster": {"name": "c-test-cluster-1234"},
"openshift": {
"infraID": "c-test-cluster-1234-xlk3f",
"clusterID": "2888efd2-8a1b-4846-82ec-3a99506e2c70",
"baseDomain": "c-test-cluster-1234.example.org",
"appsDomain": "apps.c-test-cluster-1234.example.org",
"apiURL": "api.c-test-cluster-1234.example.org",
"ssh_key": "",
},
}

0 comments on commit 3a7e144

Please sign in to comment.