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
Bug 1889721: add skippatch unit test #505
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package registry | |
|
||
import ( | ||
"encoding/json" | ||
"github.com/blang/semver" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
@@ -312,3 +313,73 @@ func TestBundleGraphLoader(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func TestIsSkipPatchCandidate(t *testing.T) { | ||
tests := []struct{ | ||
name string | ||
added string | ||
compare string | ||
expected bool | ||
commutative bool | ||
}{ | ||
{ | ||
name: "equal versions", | ||
added: "0.0.0", | ||
compare: "0.0.0", | ||
expected: false, | ||
commutative: true, | ||
}, | ||
{ | ||
name: "do not accept different major/minor version", | ||
added: "0.1.0", | ||
compare: "0.2.0", | ||
expected: false, | ||
commutative: true, | ||
}, | ||
{ | ||
name: "accept larger patch version", | ||
added: "0.0.1", | ||
compare: "0.0.0", | ||
expected: true, | ||
}, | ||
{ | ||
name: "accept patch version without pre-release", | ||
added: "0.0.0", | ||
compare: "0.0.0-1", | ||
expected: true, | ||
}, | ||
{ | ||
name: "accept longer pre-release with same prefix", | ||
added: "0.0.1-1.2", | ||
compare: "0.0.1-1", | ||
expected: true, | ||
}, | ||
{ | ||
name: "accept numerically larger pre-release", | ||
added: "0.0.1-11", | ||
compare: "0.0.1-2", | ||
expected: true, | ||
}, | ||
{ | ||
name: "accept lexicographically larger pre-release", | ||
benluddy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
added: "0.0.1-beta.1", | ||
compare: "0.0.1-alpha.1", | ||
expected: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
added, err := semver.Make(tt.added) | ||
require.NoError(t, err) | ||
compare, err := semver.Make(tt.compare) | ||
require.NoError(t, err) | ||
actual := isSkipPatchCandidate(added, compare) | ||
assert.Equal(t, tt.expected, actual) | ||
|
||
if !tt.commutative { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that I see it (and recognize that there are cases that don't have this property), I'm not sure that adding a second assertion to the test is better than explicitly writing these cases. I won't ask you to change it again if you disagree, though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can make this assertion whenever we have a valid skippatch pair. |
||
reverse := isSkipPatchCandidate(compare, added) | ||
assert.Equal(t, !tt.expected, reverse) | ||
} | ||
}) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ankitathomas if it is the following data,
is it correct? I think so. thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ankitathomas To add on to this, if
f(a, c) -> !f(c, a)
and!f(a, c) -> f(c, a)
, then this test could automatically verify both for each case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added checking for the absence of a commutative edge