Skip to content

Commit b3d9fdd

Browse files
committed
Add tests
Uses examples to check that the renderer works as expected.
1 parent cfd1873 commit b3d9fdd

File tree

5 files changed

+49
-0
lines changed

5 files changed

+49
-0
lines changed

.github/workflows/build_and_publish.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,24 @@ on:
55
- main
66
pull_request:
77
jobs:
8+
test:
9+
name: "Run tests"
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Install tools
18+
uses: asdf-vm/actions/install@v3
19+
20+
- name: Run tests
21+
run: pkl test tests.pkl
822
build_and_publish:
923
name: "Create Pkl package, tag and release"
1024
runs-on: ubuntu-latest
25+
needs: test
1126
steps:
1227
- name: Checkout code
1328
uses: actions/checkout@v3

examples/basic.pkl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import "../tfVarsRenderer.pkl"
2+
3+
one = 1
4+
two = "two"
5+
three = true
6+
7+
output {
8+
renderer = new tfVarsRenderer.TfVarsRenderer{}
9+
}

tests.pkl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
amends "pkl:test"
2+
import* "examples/*.pkl" as allExamples
3+
4+
examples {
5+
for (key in allExamples.keys) {
6+
[key.drop("examples/".length).replaceLast("pkl","tfvars")] {
7+
allExamples[key].output.text
8+
}
9+
}
10+
}

tests.pkl-expected.pcf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
examples {
2+
["basic.tfvars"] {
3+
"""
4+
one = 1
5+
two = "two"
6+
three = true
7+
"""
8+
}
9+
}

tfVarsRenderer.pkl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ class TfVarsRenderer extends ValueRenderer {
55
function renderValue(value: Any): String =
66
if (value is String)
77
"\"" + value + "\""
8+
else if (value is Int || value is Float)
9+
value.toString()
10+
else if (value is List)
11+
"[" + value.map((el) -> renderValue(el)).join(", ") + "]"
12+
else if (value is Map)
13+
"{" + value.entries.map((el) -> el.key + " = " + renderValue(el.value)).join(", ") + "}"
814
else if (value is Boolean)
915
if (value) "true" else "false"
1016
else if (value is Dynamic)

0 commit comments

Comments
 (0)