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

Bug 1889721: add skippatch unit test #505

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
71 changes: 71 additions & 0 deletions pkg/registry/bundlegraphloader_test.go
Expand Up @@ -2,6 +2,7 @@ package registry

import (
"encoding/json"
"github.com/blang/semver"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -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",

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,

{
			name: "do not accept patch version with pre-release",
			added: "0.0.0-1",
			compare: "0.0.0",
			expected: false,
		},

is it correct? I think so. thanks

Copy link
Contributor

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.

Copy link
Contributor Author

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

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can make this assertion whenever we have a valid skippatch pair. f(a, c) -> !f(c, a) holds true, so this should cover all the cases we need

reverse := isSkipPatchCandidate(compare, added)
assert.Equal(t, !tt.expected, reverse)
}
})
}
}