Skip to content

Commit

Permalink
Add test for more templating functions
Browse files Browse the repository at this point in the history
Renaming the escaping test to a general templating test and add tests
for a selection of functions from sprig-slim as well as the builtin
sector function

Signed-off-by: Sjoerd Simons <[email protected]>
  • Loading branch information
sjoerdsimons committed Dec 30, 2023
1 parent 7297885 commit 94d0610
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ jobs:
- kvm
test:
- { name: "recipes", case: "recipes" }
- { name: "escaping", case: "escaping", variables: " -t escaped:\\$ba\\'d\\$gers\\ snakes" }
- { name: "templating", case: "templating", variables: " -t escaped:\\$ba\\'d\\$gers\\ snakes" }
- { name: "debian (amd64)", case: "debian", variables: "-t architecture:amd64" }
- { name: "debian (arm64)", case: "debian", variables: "-t architecture:arm64" }
- { name: "debian (armhf)", case: "debian", variables: "-t architecture:armhf" }
Expand Down
20 changes: 0 additions & 20 deletions tests/escaping/test.yaml

This file was deleted.

37 changes: 37 additions & 0 deletions tests/templating/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# expected to be run with -t escaped:\$bad\'ge\$rs or similar to verify passing
# variables onwards
{{ $escaped := or .escaped "$mu'room$" }}
architecture: amd64

actions:
- action: run
description: test escaping in command
chroot: false
command: echo {{ escape $escaped }} > test.a
- action: run
description: escaping via heredoc
chroot: false
command: |-
cat << 'EOF' > test.b
{{ $escaped }}
EOF
- action: run
description: validate escaping
chroot: false
command: diff -u test.a test.b
- action: run
description: sector custom function
chroot: false
command: test 4096 -eq {{ sector 8 }}
- action: run
description: sprig string functions
chroot: false
command: test "HELLOHELLO" = {{ "hello" | upper | repeat 2 }}
- action: run
description: sprig integer math functions
chroot: false
command: test 42 -eq {{ mul 4 10 | add 2 }}
- action: run
description: sprig conversion function
chroot: false
command: test 42 -eq {{ 0x2a | int }}

0 comments on commit 94d0610

Please sign in to comment.