Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions e2e/testdata/live-apply/crd-and-cr/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,23 @@ stdOut: |
custom.kpt.dev/cr apply successful
apply phase finished
reconcile phase started
custom.kpt.dev/cr reconcile successful
reconcile phase finished
inventory update started
inventory update finished
apply result: 2 attempted, 2 successful, 0 skipped, 0 failed
reconcile result: 2 attempted, 2 successful, 0 skipped, 0 failed, 0 timed out

optionalStdOut:
- customresourcedefinition.apiextensions.k8s.io/customs.kpt.dev reconcile pending
- custom.kpt.dev/cr reconcile pending
- custom.kpt.dev/cr reconcile successful
- custom.kpt.dev/cr reconcile timeout
- "reconcile result: 2 attempted, 2 successful, 0 skipped, 0 failed, 0 timed out"
- "reconcile result: 2 attempted, 1 successful, 0 skipped, 0 failed, 1 timed out"

inventory:
- group: apiextensions.k8s.io
kind: CustomResourceDefinition
name: customs.kpt.dev
- group: kpt.dev
kind: Custom
name: cr
name: cr
5 changes: 4 additions & 1 deletion internal/builtins/pkg_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"bytes"
"os"
"path/filepath"
"strings"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -62,7 +63,9 @@ func TestPkgContextGenerator(t *testing.T) {
if err != test.expErr {
t.Errorf("exp: %v got: %v", test.expErr, err)
}
if diff := cmp.Diff(string(exp), out.String()); diff != "" {
expected := strings.ReplaceAll(string(exp), "\r\n", "\n")
actual := strings.ReplaceAll(out.String(), "\r\n", "\n")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use that normalizeLineEndings function here

if diff := cmp.Diff(expected, actual); diff != "" {
t.Errorf("pkg context mistmach (-want +got):\n%s", diff)
}
})
Expand Down
27 changes: 23 additions & 4 deletions internal/util/get/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1"
"github.com/kptdev/kpt/pkg/printer/fake"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"sigs.k8s.io/kustomize/kyaml/kio"
"sigs.k8s.io/kustomize/kyaml/kio/filters"
"sigs.k8s.io/kustomize/kyaml/yaml"
Expand Down Expand Up @@ -213,15 +214,33 @@ func TestCommand_Run_subdir_symlinks(t *testing.T) {
}.Run(fake.CtxWithPrinter(cliOutput, cliOutput))
assert.NoError(t, err)

// ensure warning for symlink is printed on the CLI
assert.Contains(t, cliOutput.String(), `[Warn] Ignoring symlink "config-symlink"`)
sourceSymlinkPath := filepath.Join(g.DatasetDirectory, testutil.Dataset6, subdir, "config-symlink")
info, statErr := os.Lstat(sourceSymlinkPath)
isSymlinkInSource := false
if statErr == nil {
isSymlinkInSource = info.Mode()&os.ModeSymlink != 0
} else if !os.IsNotExist(statErr) {
require.NoError(t, statErr)
}

if isSymlinkInSource {
// ensure warning for symlink is printed on the CLI
assert.Contains(t, cliOutput.String(), `[Warn] Ignoring symlink "config-symlink"`)
} else {
// on environments without symlink materialization, there is no ignore warning
assert.NotContains(t, cliOutput.String(), `[Warn] Ignoring symlink "config-symlink"`)
}

// verify the cloned contents do not contains symlinks
diff, err := testutil.Diff(filepath.Join(g.DatasetDirectory, testutil.Dataset6, subdir), absPath, true)
assert.NoError(t, err)
diff = diff.Difference(testutil.KptfileSet)
// original repo contains symlink and cloned doesn't, so the difference
assert.Contains(t, diff.List(), "config-symlink")
if isSymlinkInSource {
// original repo contains symlink and cloned doesn't, so the difference
assert.Contains(t, diff.List(), "config-symlink")
} else {
assert.NotContains(t, diff.List(), "config-symlink")
}

// verify the KptFile contains the expected values
commit, err := g.GetCommit()
Expand Down
16 changes: 11 additions & 5 deletions internal/util/render/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ kind: Kptfile
metadata:
name: root-package
annotations:
kpt.dev/bfs-rendering: %t
kpt.dev/bfs-rendering: "%t"
`, renderBfs))
assert.NoError(t, err)

Expand Down Expand Up @@ -341,8 +341,12 @@ func TestRenderer_Execute_RenderOrder(t *testing.T) {
renderer, outputBuffer, ctx := setupRendererTest(t, tc.renderBfs)

fnResults, err := renderer.Execute(ctx)
assert.NoError(t, err)
assert.NotNil(t, fnResults)
if !assert.NoError(t, err) {
return
}
if !assert.NotNil(t, fnResults) {
return
}
assert.Equal(t, 0, len(fnResults.Items))

output := outputBuffer.String()
Expand Down Expand Up @@ -426,7 +430,7 @@ kind: Kptfile
metadata:
name: root-package
annotations:
ktp.dev/bfs-rendering: true
kpt.dev/bfs-rendering: "true"
`))
assert.NoError(t, err)

Expand All @@ -440,7 +444,9 @@ metadata:

// Create a mock hydration context
root, err := newPkgNode(mockFileSystem, rootPkgPath, nil)
assert.NoError(t, err)
if !assert.NoError(t, err) {
return
}

hctx := &hydrationContext{
root: root,
Expand Down
Loading
Loading