This repository was archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathunittests.jsonnet
79 lines (78 loc) · 2.75 KB
/
unittests.jsonnet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
local kube = import "../kube.libsonnet";
local an_obj = kube._Object("v1", "Gentle", "foo");
local a_pod = kube.Pod("foo") {
metadata+: { labels+: { foo: "bar", bar: "qxx" } },
spec+: {
default_container: "c1",
containers_+: {
local c = self,
c1: kube.Container("c1") {
image: "nginx",
args_: {
k1: "v1",
k2: "v2",
},
ports_: {
http: { containerPort: 8080 },
https: { containerPort: 8443 },
udp: { containerPort: 5353, protocol: "UDP" },
},
},
c2: kube.Container("c2") {
image: "nginx",
args_format+: { prefix: "-" },
args_: c.c1.args_,
},
c3: kube.Container("c3") {
image: "nginx",
args_format+: { split: true },
args_: c.c1.args_,
},
c4: kube.Container("c4") {
image: "nginx",
args_format+: { prefix: "-", split: true },
args_: c.c1.args_,
},
},
},
};
local a_deploy = kube.Deployment("foo") {
spec+: { template+: { metadata+: a_pod.metadata, spec+: a_pod.spec } },
};
// Basic unittesting for methods that are not exercised by the other e2e-ish tests
std.assertEqual(a_pod.spec.containers[0].args, ["--k1=v1", "--k2=v2"]) &&
std.assertEqual(a_pod.spec.containers[1].args, ["-k1=v1", "-k2=v2"]) &&
std.assertEqual(a_pod.spec.containers[2].args, ["--k1", "v1", "--k2", "v2"]) &&
std.assertEqual(a_pod.spec.containers[3].args, ["-k1", "v1", "-k2", "v2"]) &&
std.assertEqual(kube.objectValues({ a: 1, b: 2 }), [1, 2]) &&
std.assertEqual(kube.objectItems({ a: 1, b: 2 }), [["a", 1], ["b", 2]]) &&
std.assertEqual(kube.hyphenate("foo_bar_baz"), ("foo-bar-baz")) &&
std.assertEqual(kube.mapToNamedList({ foo: { a: "b" } }), [{ name: "foo", a: "b" }]) &&
std.assertEqual(kube.filterMapByFields({ a: 1, b: 2, c: 3 }, ["a", "c", "d"]), { a: 1, c: 3 }) &&
std.assertEqual(kube.parseOctal("755"), 493) &&
std.assertEqual(kube.siToNum("42G"), 42 * 1e9) &&
std.assertEqual(kube.siToNum("42Gi"), 42 * std.pow(2, 30)) &&
std.assertEqual(kube.toUpper("ForTy 2"), "FORTY 2") &&
std.assertEqual(kube.toLower("ForTy 2"), "forty 2") &&
std.assertEqual(an_obj, {
apiVersion: "v1",
kind: "Gentle",
metadata: { name: "foo", labels: { name: "foo" }, annotations: {} },
}) &&
std.assertEqual(
[kube.podRef(a_deploy).spec.ports("TCP"), kube.podRef(a_deploy).spec.ports("UDP")],
[[8080, 8443], [5353]]
) &&
std.assertEqual(
// latest kubecfg produces stable output from maps hashes, so below shouldn't be flaky
kube.podsPorts([a_deploy]),
[
{ port: 8080, protocol: "TCP" },
{ port: 8443, protocol: "TCP" },
{ port: 5353, protocol: "UDP" },
]
) &&
std.assertEqual(
kube.podLabelsSelector(a_deploy),
{ podSelector: { matchLabels: { name: "foo", foo: "bar", bar: "qxx" } } }
)