Skip to content

Commit f364e99

Browse files
committed
Make sure that all the standard templates are embedded correctly
Signed-off-by: Jan Dubois <[email protected]>
1 parent 6dabf34 commit f364e99

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

hack/test-port-forwarding.pl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,11 @@ sub JoinHostPort {
212212
# "ipv4" and "ipv6" will be replaced by the actual host ipv4 and ipv6 addresses.
213213
__DATA__
214214
portForwards:
215-
# We can't test that port 22 will be blocked because the guestagent has
216-
# been ignoring it since startup, so the log message is in the part of
217-
# the log we skipped.
218-
# skip: 127.0.0.1 22 → 127.0.0.1 2222
219-
# ignore: 127.0.0.1 sshLocalPort
215+
# We can't test that port 22 will be blocked because the guestagent has
216+
# been ignoring it since startup, so the log message is in the part of
217+
# the log we skipped.
218+
# skip: 127.0.0.1 22 → 127.0.0.1 2222
219+
# ignore: 127.0.0.1 sshLocalPort
220220
221221
- guestIP: 127.0.0.2
222222
guestPortRange: [3000, 3009]

hack/test-templates.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ if [ "$#" -ne 1 ]; then
1717
exit 1
1818
fi
1919

20-
FILE="$1"
20+
# Resolve any ../ fragments in the filename because they are invalid in relative template locators
21+
FILE="$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
2122
NAME="$(basename -s .yaml "$FILE")"
2223
OS_HOST="$(uname -o)"
2324

@@ -135,6 +136,9 @@ if [[ -n ${CHECKS["port-forwards"]} ]]; then
135136
limactl validate "$FILE_HOST"
136137
fi
137138

139+
INFO "Make sure template embedding copies \"$FILE\" exactly"
140+
diff -u <(echo -n "base: $FILE" | limactl tmpl copy --embed - -) "$FILE"
141+
138142
function diagnose() {
139143
NAME="$1"
140144
set -x +e

pkg/limatmpl/embed.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package limatmpl
22

33
import (
4+
"bytes"
45
"context"
56
"fmt"
67
"os"
@@ -130,10 +131,12 @@ func (tmpl *Template) embedBase(ctx context.Context, baseLocator limayaml.Locato
130131

131132
// evalExprImpl evaluates tmpl.expr against one or more documents.
132133
// Called by evalExpr() and embedAllScripts() for single documents and merge() for 2 documents.
133-
func (tmpl *Template) evalExprImpl(prefix string, bytes []byte) error {
134+
func (tmpl *Template) evalExprImpl(prefix string, b []byte) error {
134135
var err error
135136
expr := prefix + tmpl.expr.String() + "| $a"
136-
tmpl.Bytes, err = yqutil.EvaluateExpression(expr, bytes)
137+
tmpl.Bytes, err = yqutil.EvaluateExpression(expr, b)
138+
// Make sure the YAML ends with just a single newline
139+
tmpl.Bytes = append(bytes.TrimRight(tmpl.Bytes, "\n"), '\n')
137140
tmpl.Config = nil
138141
tmpl.expr.Reset()
139142
return tmpl.ClearOnError(err)

0 commit comments

Comments
 (0)