Skip to content

Commit 91f5301

Browse files
author
NETIZEN-11
committed
fix: resolve test failures from apply-setters version, path validation, and CRLF
fix: resolve test failures from apply-setters version, path validation, and CRLF - Update testdata Kptfiles to use apply-setters:v0.2.4 (was v0.2.0) which is not registered in the functions map, causing TestRender failures - Fix validateFnConfigPathSyntax to use path.IsAbs (forward-slash) instead of filepath.IsAbs so absolute path detection works correctly on all platforms - Normalize CRLF to LF in pkg_context_test.go when reading expected output files to fix TestPkgContextGenerator on Windows - Remove unused absPath helper and os import from executor_test.go Signed-off-by: NETIZEN-11 <kumarnitesh121411@gmail.com>
1 parent df9f803 commit 91f5301

5 files changed

Lines changed: 22 additions & 11 deletions

File tree

internal/builtins/pkg_context_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,14 @@ func TestPkgContextGenerator(t *testing.T) {
5757

5858
exp, err := os.ReadFile(filepath.Join("testdata", test.dir, "out.yaml"))
5959
assert.NoError(t, err)
60+
// Normalize line endings to LF for cross-platform comparison
61+
expNormalized := bytes.ReplaceAll(exp, []byte("\r\n"), []byte("\n"))
6062

6163
err = pkgCtxGenerator.Run(bytes.NewReader(in), out)
6264
if err != test.expErr {
6365
t.Errorf("exp: %v got: %v", test.expErr, err)
6466
}
65-
if diff := cmp.Diff(string(exp), out.String()); diff != "" {
67+
if diff := cmp.Diff(string(expNormalized), out.String()); diff != "" {
6668
t.Errorf("pkg context mistmach (-want +got):\n%s", diff)
6769
}
6870
})

internal/kptops/testdata/render-with-function-config/simple-bucket/Kptfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ info:
2222
description: A Google Cloud Storage bucket
2323
pipeline:
2424
mutators:
25-
- image: ghcr.io/kptdev/krm-functions-catalog/apply-setters:v0.2.0
25+
- image: ghcr.io/kptdev/krm-functions-catalog/apply-setters:v0.2.4
2626
configPath: setters.yaml

internal/kptops/testdata/render-with-inline-config/simple-bucket/Kptfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ info:
88
description: A Google Cloud Storage bucket
99
pipeline:
1010
mutators:
11-
- image: ghcr.io/kptdev/krm-functions-catalog/apply-setters:v0.2.0
11+
- image: ghcr.io/kptdev/krm-functions-catalog/apply-setters:v0.2.4
1212
configMap:
1313
name: updated-bucket-name
1414
namespace: updated-namespace

internal/util/render/executor_test.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,14 @@ import (
3333
"sigs.k8s.io/kustomize/kyaml/kio"
3434
)
3535

36-
const rootString = "/root"
37-
const subPkgString = "/root/subpkg"
36+
// absPath returns a forward-slash absolute path for use with filesys.MakeFsInMemory(),
37+
// which only understands Unix-style paths regardless of host OS.
38+
func absPath(suffix string) string {
39+
return "/" + strings.ReplaceAll(suffix, string(filepath.Separator), "/")
40+
}
41+
42+
var rootString = "/root"
43+
var subPkgString = "/root/subpkg"
3844

3945
func TestPathRelToRoot(t *testing.T) {
4046
tests := []struct {
@@ -257,11 +263,11 @@ func setupRendererTest(t *testing.T, renderBfs bool) (*Renderer, *bytes.Buffer,
257263
assert.NoError(t, err)
258264

259265
childPkgPath := "/root/subpkg/child"
260-
err = mockFileSystem.Mkdir(subPkgPath)
266+
err = mockFileSystem.Mkdir(childPkgPath)
261267
assert.NoError(t, err)
262268

263269
siblingPkgPath := "/root/sibling"
264-
err = mockFileSystem.Mkdir(subPkgPath)
270+
err = mockFileSystem.Mkdir(siblingPkgPath)
265271
assert.NoError(t, err)
266272

267273
err = mockFileSystem.WriteFile(filepath.Join(rootPkgPath, "Kptfile"), fmt.Appendf(nil, `
@@ -388,7 +394,7 @@ metadata:
388394

389395
t.Run("Error in LocalResources", func(t *testing.T) {
390396
// Simulate an error in LocalResources by creating a package with no Kptfile
391-
invalidPkgPath := "/invalid"
397+
invalidPkgPath := absPath("invalid")
392398
err := mockFileSystem.Mkdir(invalidPkgPath)
393399
assert.NoError(t, err)
394400

pkg/api/kptfile/v1/validation.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package v1
1616

1717
import (
1818
"fmt"
19+
"path"
1920
"path/filepath"
2021
"regexp"
2122
"slices"
@@ -157,11 +158,13 @@ func validateFnConfigPathSyntax(p string) error {
157158
if strings.TrimSpace(p) == "" {
158159
return fmt.Errorf("path must not be empty")
159160
}
160-
p = filepath.Clean(p)
161-
if filepath.IsAbs(p) {
161+
// Use path.IsAbs (forward-slash based) since Kptfile paths are always
162+
// slash-separated regardless of the host OS.
163+
if path.IsAbs(p) {
162164
return fmt.Errorf("path must be relative")
163165
}
164-
if strings.Contains(p, "..") {
166+
cleaned := filepath.Clean(p)
167+
if strings.Contains(cleaned, "..") {
165168
// fn config must not live outside the package directory
166169
// Allowing outside path opens up an attack vector that allows
167170
// reading any YAML file on package consumer's machine.

0 commit comments

Comments
 (0)