Skip to content

Commit 0501ce0

Browse files
committed
fix: for local var example code add more unit test cases
Signed-off-by: peefy <xpf6677@163.com>
1 parent b1a8b9b commit 0501ce0

File tree

7 files changed

+31
-7
lines changed

7 files changed

+31
-7
lines changed

blog/2023-05-30-vs-helm/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,13 @@ spec = {
328328
template.metadata.labels = metadata.labels
329329
template.spec.containers = [
330330
{
331-
name = name
331+
name = n
332332
image = container.image.name
333333
command = container.command
334334
command = container.args
335335
env = container.env
336336
resources = container.resources
337-
} for name, container in option("containers") or {}
337+
} for n, container in option("containers") or {}
338338
]
339339
}
340340
EOF

examples/gitops/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test:
2+
make -C config

examples/gitops/config/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
test:
2+
kcl run
3+
kcl test

examples/gitops/config/kubernetes_render.k

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ kubernetesRender = lambda a: app.App {
1616
template.metadata.labels = a.labels
1717
template.spec.containers = [
1818
{
19-
name = name
19+
name = n
2020
image = c.image
2121
command = c.command
2222
args = c.args
2323
env = c.env
2424
volumeMounts = c.volumes
2525
resources: c.resources
2626
ports = c.ports
27-
} for name, c in a.containers
27+
} for n, c in a.containers
2828
]
2929
}
3030
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import manifests
2+
3+
import app
4+
5+
# Convert the `App` model into Kubernetes Deployment and Service Manifests
6+
test_kubernetesRender = lambda {
7+
a = app.App {
8+
name = "app"
9+
containers.ngnix = {
10+
image = "ngnix"
11+
ports = [{containerPort = 80}]
12+
}
13+
service.ports = [{ port = 80 }]
14+
}
15+
resources = kubernetesRender(a)
16+
assert resources[0].kind == "Deployment"
17+
assert resources[1].kind == "Service"
18+
assert resources[0].spec.template.spec.containers[0]["name"] == "ngnix", "expected {}, got {}".format("", resources[0].spec.template.spec.containers[0]["name"])
19+
}

examples/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pwd=$(
1313
pwd
1414
)
1515

16-
for path in "configuration" "validation" "abstraction" "definition" "mutation" "data-integration" "automation" "package-management" "kubernetes" "codelab"; do
16+
for path in "configuration" "validation" "abstraction" "definition" "gitops" "mutation" "data-integration" "automation" "package-management" "kubernetes" "codelab"; do
1717
echo "\033[1mTesting $path ...\033[0m"
1818
if (cd $pwd/$path && make test); then
1919
echo "\033[32mTest SUCCESSED - $path\033[0m\n"

i18n/zh-CN/docusaurus-plugin-content-blog/2023-05-30-vs-helm/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,13 @@ spec = {
324324
template.metadata.labels = metadata.labels
325325
template.spec.containers = [
326326
{
327-
name = name
327+
name = n
328328
image = container.image.name
329329
command = container.command
330330
command = container.args
331331
env = container.env
332332
resources = container.resources
333-
} for name, container in option("containers") or {}
333+
} for n, container in option("containers") or {}
334334
]
335335
}
336336
EOF

0 commit comments

Comments
 (0)