Skip to content

feat: Allow suppress diff line output by regex #475

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

Merged
merged 8 commits into from
Aug 21, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Added unit tests
Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
  • Loading branch information
jkroepke committed Jun 28, 2023
commit 445d42cbc89b9e815bb532a21d64ffbafcff72e9
57 changes: 57 additions & 0 deletions diff/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,17 @@ spec:
`, buf1.String())
})

t.Run("OnChangeWithSuppress", func(t *testing.T) {
var buf1 bytes.Buffer
diffOptions := Options{"diff", 10, false, true, []string{}, 0.0, []string{"apiVersion"}}

if changesSeen := Manifests(specBeta, specRelease, &diffOptions, &buf1); !changesSeen {
t.Error("Unexpected return value from Manifests: Expected the return value to be `true` to indicate that it has seen any change(s), but was `false`")
}

require.Equal(t, ``, buf1.String())
})

t.Run("OnChangeRename", func(t *testing.T) {
var buf1 bytes.Buffer
diffOptions := Options{"diff", 10, false, true, []string{}, 0.5, []string{}}
Expand Down Expand Up @@ -341,6 +352,29 @@ spec:
+ matchLabels:
+ app: nginx-renamed

`, buf1.String())
})

t.Run("OnChangeRenameAndAddedWithPartialSuppress", func(t *testing.T) {
var buf1 bytes.Buffer
diffOptions := Options{"diff", 10, false, true, []string{}, 0.5, []string{"app: "}}

if changesSeen := Manifests(specReleaseSpec, specReleaseRenamedAndAdded, &diffOptions, &buf1); !changesSeen {
t.Error("Unexpected return value from Manifests: Expected the return value to be `true` to indicate that it has seen any change(s), but was `false`")
}

require.Equal(t, `default, nginx, Deployment (apps) has changed:

apiVersion: apps/v1
kind: Deployment
metadata:
- name: nginx
+ name: nginx-renamed
spec:
replicas: 3
+ selector:
+ matchLabels:

`, buf1.String())
})

Expand All @@ -365,6 +399,29 @@ spec:
- matchLabels:
- app: nginx-renamed

`, buf1.String())
})

t.Run("OnChangeRenameAndRemovedWithPartialSuppress", func(t *testing.T) {
var buf1 bytes.Buffer
diffOptions := Options{"diff", 10, false, true, []string{}, 0.5, []string{"app: "}}

if changesSeen := Manifests(specReleaseRenamedAndAdded, specReleaseSpec, &diffOptions, &buf1); !changesSeen {
t.Error("Unexpected return value from Manifests: Expected the return value to be `true` to indicate that it has seen any change(s), but was `false`")
}

require.Equal(t, `default, nginx-renamed, Deployment (apps) has changed:

apiVersion: apps/v1
kind: Deployment
metadata:
- name: nginx-renamed
+ name: nginx
spec:
replicas: 3
- selector:
- matchLabels:

`, buf1.String())
})

Expand Down