Skip to content

Commit 14b6902

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

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

hack/test-port-forwarding.pl

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

hack/test-templates.sh

+3
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ if [[ -n ${CHECKS["port-forwards"]} ]]; then
104104
limactl validate "$FILE"
105105
fi
106106

107+
INFO "Make sure template embedding copies \"$FILE\" exactly"
108+
diff -u <(echo -n "base: $FILE" | limactl tmpl copy --embed - -) "$FILE"
109+
107110
function diagnose() {
108111
NAME="$1"
109112
set -x +e

pkg/limatmpl/embed.go

+5-2
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)