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

feat(between): add ignore value changes flag #412

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions internal/cmd/between.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ types are: YAML (http://yaml.org/) and JSON (http://json.org/).
report = report.ExcludeRegexp(reportOptions.excludeRegexps...)
}

if reportOptions.ignoreValueChanges {
report = report.IgnoreValueChanges()
}

return writeReport(cmd, report)
},
}
Expand Down
19 changes: 19 additions & 0 deletions internal/cmd/cmds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,25 @@ spec.replicas (apps/v1/Deployment/test)
Expect(err).ToNot(HaveOccurred())
Expect(out).To(BeEquivalentTo("\n"))
})

It("should ignore the changes in values", func() {
expected := `
(file level)
- one document removed:
---
apiVersion: v1
kind: Namespace
metadata:
name: test

`
By("using the --ignore-value-changes", func() {
out, err := dyff("between", "--omit-header", "--ignore-value-changes", assets("issues", "issue-232", "from.yml"), assets("issues", "issue-232", "to.yml"))
Expect(err).ToNot(HaveOccurred())
Expect(out).To(BeEquivalentTo(expected))
})

})
})

Context("last-applied command", func() {
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type reportConfig struct {
exitWithCode bool
omitHeader bool
useGoPatchPaths bool
ignoreValueChanges bool
minorChangeThreshold float64
multilineContextLines int
additionalIdentifiers []string
Expand Down Expand Up @@ -87,7 +88,7 @@ func applyReportOptionsFlags(cmd *cobra.Command) {
cmd.Flags().StringSliceVar(&reportOptions.excludes, "exclude", defaults.excludes, "exclude reports from a set of differences based on supplied arguments")
cmd.Flags().StringSliceVar(&reportOptions.filterRegexps, "filter-regexp", defaults.filterRegexps, "filter reports to a subset of differences based on supplied regular expressions")
cmd.Flags().StringSliceVar(&reportOptions.excludeRegexps, "exclude-regexp", defaults.excludeRegexps, "exclude reports from a set of differences based on supplied regular expressions")

cmd.Flags().BoolVarP(&reportOptions.ignoreValueChanges, "ignore-value-changes", "v", false, "exclude changes in values")
// Main output preferences
cmd.Flags().StringVarP(&reportOptions.style, "output", "o", defaults.style, "specify the output style, supported styles: human, brief, github, gitlab, gitea")
cmd.Flags().BoolVarP(&reportOptions.omitHeader, "omit-header", "b", defaults.omitHeader, "omit the dyff summary header")
Expand Down
23 changes: 23 additions & 0 deletions pkg/dyff/reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,26 @@ func (r Report) ExcludeRegexp(pattern ...string) (result Report) {
return true
})
}

func (r Report) IgnoreValueChanges() (result Report) {
result = Report{
From: r.From,
To: r.To,
}

for _, diff := range r.Diffs {
var hasValChange = false
for _, detail := range diff.Details {
if detail.Kind == MODIFICATION {
hasValChange = true
break
}
}

if !hasValChange {
result.Diffs = append(result.Diffs, diff)
}
}

return result
}