Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for nonexistent pkg/kptfile. #1818

Merged
merged 1 commit into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 0 additions & 3 deletions internal/cmddiff/cmddiff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func TestMain(m *testing.M) {
func TestCmdInvalidDiffType(t *testing.T) {
runner := cmddiff.NewRunner(fake.CtxWithNilPrinter(), "")
runner.C.SetArgs([]string{"--diff-type", "invalid"})
runner.C.SilenceErrors = true
Copy link
Contributor

Choose a reason for hiding this comment

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

Why these changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not necessary but the silencing of the errors didn't affect the tests at all. Can undo if we prefer to keep that true.

err := runner.C.Execute()
assert.EqualError(t,
err,
Expand All @@ -43,7 +42,6 @@ func TestCmdInvalidDiffType(t *testing.T) {
func TestCmdInvalidDiffTool(t *testing.T) {
runner := cmddiff.NewRunner(fake.CtxWithNilPrinter(), "")
runner.C.SetArgs([]string{"--diff-tool", "nodiff"})
runner.C.SilenceErrors = true
err := runner.C.Execute()
assert.EqualError(t,
err,
Expand All @@ -68,7 +66,6 @@ func TestCmdExecute(t *testing.T) {

runner := cmddiff.NewRunner(fake.CtxWithNilPrinter(), "")
runner.C.SetArgs([]string{dest, "--diff-type", "local"})
runner.C.SilenceErrors = true
err = runner.C.Execute()
assert.NoError(t, err)
}
42 changes: 41 additions & 1 deletion internal/util/diff/pkgdiff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestPkgDiff(t *testing.T) {
diff: toStringSet("Kptfile"),
},
{
name: "subpackages are not included",
name: "subpackages are not included in no diff",
pkg1: pkgbuilder.NewRootPkg().
WithKptfile().
WithResource(pkgbuilder.DeploymentResource).
Expand All @@ -94,6 +94,46 @@ func TestPkgDiff(t *testing.T) {
),
diff: toStringSet(),
},
{
name: "subpackages are not included in root package diff",
pkg1: pkgbuilder.NewRootPkg().
WithKptfile().
WithResource(pkgbuilder.ConfigMapResource).
WithSubPackages(
pkgbuilder.NewSubPkg("subpackage").
WithKptfile(pkgbuilder.NewKptfile()).
WithResource(pkgbuilder.DeploymentResource),
),
pkg2: pkgbuilder.NewRootPkg().
WithKptfile().
WithResource(pkgbuilder.DeploymentResource).
WithSubPackages(
pkgbuilder.NewSubPkg("subpackage").
WithKptfile().
WithResource(pkgbuilder.ConfigMapResource),
),
diff: toStringSet("deployment.yaml", "configmap.yaml"),
},
{
name: "package doesn't exist",
pkg1: nil,
pkg2: pkgbuilder.NewRootPkg().
WithKptfile(pkgbuilder.NewKptfile()),
diff: toStringSet("Kptfile"),
},
{
name: "package doesn't have a kptfile",
pkg1: pkgbuilder.NewRootPkg(),
pkg2: pkgbuilder.NewRootPkg().
WithKptfile().
WithResource(pkgbuilder.DeploymentResource).
WithSubPackages(
pkgbuilder.NewSubPkg("subpackage").
WithKptfile().
WithResource(pkgbuilder.ConfigMapResource),
),
diff: toStringSet("Kptfile", "deployment.yaml"),
},
}

for i := range testCases {
Expand Down