commit
614398db41
|
@ -69,7 +69,7 @@ func shouldUpdate(spt SemverPolicyType, matchPreRelease bool, current, new strin
|
|||
}
|
||||
|
||||
parts := strings.SplitN(new, ".", 3)
|
||||
if len(parts) != 3 {
|
||||
if len(parts) != 2 && len(parts) != 3 {
|
||||
return false, ErrNoMajorMinorPatchElementsFound
|
||||
}
|
||||
|
||||
|
|
|
@ -47,6 +47,16 @@ func Test_shouldUpdate(t *testing.T) {
|
|||
want: false,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "minor increase - 2 points, policy all",
|
||||
args: args{
|
||||
current: "1.4",
|
||||
new: "1.5",
|
||||
spt: SemverPolicyTypeAll,
|
||||
},
|
||||
want: true,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "minor increase, policy major",
|
||||
args: args{
|
||||
|
@ -77,6 +87,26 @@ func Test_shouldUpdate(t *testing.T) {
|
|||
want: true,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "patch release, policy patch",
|
||||
args: args{
|
||||
current: "1.4",
|
||||
new: "1.4.6",
|
||||
spt: SemverPolicyTypePatch,
|
||||
},
|
||||
want: true,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "minor and patch release, policy patch",
|
||||
args: args{
|
||||
current: "1.4",
|
||||
new: "1.5.6",
|
||||
spt: SemverPolicyTypePatch,
|
||||
},
|
||||
want: false,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "patch decrease, policy patch",
|
||||
args: args{
|
||||
|
@ -87,6 +117,16 @@ func Test_shouldUpdate(t *testing.T) {
|
|||
want: false,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "2 points minor change, policy patch",
|
||||
args: args{
|
||||
current: "1.4",
|
||||
new: "1.5",
|
||||
spt: SemverPolicyTypePatch,
|
||||
},
|
||||
want: false,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "patch AND major increase, policy patch",
|
||||
args: args{
|
||||
|
@ -117,6 +157,16 @@ func Test_shouldUpdate(t *testing.T) {
|
|||
want: true,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "minor increase 2 points, policy minor",
|
||||
args: args{
|
||||
current: "1.4",
|
||||
new: "1.5",
|
||||
spt: SemverPolicyTypeMinor,
|
||||
},
|
||||
want: true,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "patch increase, policy minor",
|
||||
args: args{
|
||||
|
|
|
@ -152,7 +152,7 @@ func exists(tag string, events []types.Event) bool {
|
|||
func semverSort(tags []string) []*semver.Version {
|
||||
var versions []*semver.Version
|
||||
for _, t := range tags {
|
||||
if len(strings.SplitN(t, ".", 3)) < 3 {
|
||||
if len(strings.SplitN(t, ".", 3)) < 2 {
|
||||
// Keep only X.Y.Z+ semver
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -130,6 +130,14 @@ func testRunHelper(testCases []runTestCase, availableTags []string, t *testing.T
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
func TestWatchAllTagsJobWith2pointSemver(t *testing.T) {
|
||||
availableTags := []string{"1.3", "2.5", "2.7", "3.8"}
|
||||
testRunHelper([]runTestCase{{"1.3", "3.8", policy.NewSemverPolicy(policy.SemverPolicyTypeMajor, false)}}, availableTags, t)
|
||||
testRunHelper([]runTestCase{{"2.5", "3.8", policy.NewSemverPolicy(policy.SemverPolicyTypeMajor, false)}}, availableTags, t)
|
||||
testRunHelper([]runTestCase{{"2.5", "2.7", policy.NewSemverPolicy(policy.SemverPolicyTypeMinor, false)}}, availableTags, t)
|
||||
}
|
||||
|
||||
func TestWatchAllTagsJobWithSemver(t *testing.T) {
|
||||
availableTags := []string{"1.3.0-dev", "1.5.0", "1.8.0-alpha"}
|
||||
testCases := []runTestCase{{"1.1.0", "1.5.0", policy.NewSemverPolicy(policy.SemverPolicyTypeMajor, true)}}
|
||||
|
@ -155,6 +163,13 @@ func TestWatchAllTagsFullSemver(t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
func TestWatchAllTagsHiddenMinorWith2PointVersions(t *testing.T) {
|
||||
availableTags := []string{"1.3", "1.5", "2.0", "1.2.1"}
|
||||
testRunHelper([]runTestCase{{"1.2", "1.2.1", policy.NewSemverPolicy(policy.SemverPolicyTypePatch, false)}}, availableTags, t)
|
||||
testRunHelper([]runTestCase{{"1.2", "1.5", policy.NewSemverPolicy(policy.SemverPolicyTypeMinor, false)}}, availableTags, t)
|
||||
testRunHelper([]runTestCase{{"1.2", "2.0", policy.NewSemverPolicy(policy.SemverPolicyTypeMajor, false)}}, availableTags, t)
|
||||
}
|
||||
|
||||
// Bug #490: new major version "hiding" minor one
|
||||
func TestWatchAllTagsHiddenMinor(t *testing.T) {
|
||||
availableTags := []string{"1.3.0", "1.5.0", "2.0.0", "1.2.1"}
|
||||
|
|
|
@ -32,7 +32,7 @@ func MustParse(version string) *types.Version {
|
|||
func GetVersion(version string) (*types.Version, error) {
|
||||
|
||||
parts := strings.SplitN(version, ".", 3)
|
||||
if len(parts) != 3 {
|
||||
if len(parts) != 2 && len(parts) != 3 {
|
||||
return nil, ErrNoMajorMinorPatchElementsFound
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,12 @@ func TestGetVersionFromImageName(t *testing.T) {
|
|||
want: MustParse("0.1.14"),
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "2 point semver, missing minor",
|
||||
args: args{name: "index.docker.io/application:12.14"},
|
||||
want: MustParse("12.14"),
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "non semver, missing minor and patch",
|
||||
args: args{name: "index.docker.io/application:42"},
|
||||
|
|
Loading…
Reference in New Issue