-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement more flexible release filtering rules
This commit adds three new options: - KeepReleases: how many releases should be returned starting from the latest - OnlyLatestMinor: if true returns only the latest minor.patch per major - OnlyLatestPatch: if true returns only the latest patch for each minor. OnlyLatestMinor has precedence over this Signed-off-by: Matias Pan <[email protected]>
- Loading branch information
Showing
4 changed files
with
234 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
package main | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestGetFilteredReleases(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
params Parameters | ||
releases []Release | ||
expectedReleases []Release | ||
}{ | ||
{ | ||
name: "no filter", | ||
params: Parameters{ | ||
MinRelease: "v0.0.0", | ||
}, | ||
releases: []Release{ | ||
{Name: "v0.0.0"}, | ||
{Name: "v0.0.1"}, | ||
{Name: "v0.1.0"}, | ||
{Name: "v1.0.0"}, | ||
}, | ||
expectedReleases: []Release{ | ||
{Name: "v0.0.0", NameSlug: "v0-0-0"}, | ||
{Name: "v0.0.1", NameSlug: "v0-0-1"}, | ||
{Name: "v0.1.0", NameSlug: "v0-1-0"}, | ||
{Name: "v1.0.0", NameSlug: "v1-0-0"}, | ||
}, | ||
}, | ||
{ | ||
name: "only latest minor", | ||
params: Parameters{ | ||
MinRelease: "v0.0.0", | ||
OnlyLatestMinor: true, | ||
}, | ||
releases: []Release{ | ||
{Name: "v0.0.0"}, | ||
{Name: "v0.0.1"}, | ||
{Name: "v0.1.0"}, | ||
{Name: "v0.1.1"}, | ||
{Name: "v1.0.0"}, | ||
{Name: "v1.0.1"}, | ||
}, | ||
expectedReleases: []Release{ | ||
{Name: "v0.1.1", NameSlug: "v0-1-1"}, | ||
{Name: "v1.0.1", NameSlug: "v1-0-1"}, | ||
}, | ||
}, | ||
{ | ||
name: "only latest patch", | ||
params: Parameters{ | ||
MinRelease: "v0.0.0", | ||
OnlyLatestPatch: true, | ||
}, | ||
releases: []Release{ | ||
{Name: "v0.0.0"}, | ||
{Name: "v0.0.1"}, | ||
{Name: "v0.1.0"}, | ||
{Name: "v0.1.1"}, | ||
}, | ||
expectedReleases: []Release{ | ||
{Name: "v0.0.1", NameSlug: "v0-0-1"}, | ||
{Name: "v0.1.1", NameSlug: "v0-1-1"}, | ||
}, | ||
}, | ||
{ | ||
name: "only latest minor has precedence", | ||
params: Parameters{ | ||
MinRelease: "v0.0.0", | ||
OnlyLatestMinor: true, | ||
OnlyLatestPatch: true, | ||
}, | ||
releases: []Release{ | ||
{Name: "v0.0.0"}, | ||
{Name: "v0.0.1"}, | ||
{Name: "v0.1.0"}, | ||
{Name: "v0.1.1"}, | ||
{Name: "v1.0.0"}, | ||
{Name: "v1.0.1"}, | ||
}, | ||
expectedReleases: []Release{ | ||
{Name: "v0.1.1", NameSlug: "v0-1-1"}, | ||
{Name: "v1.0.1", NameSlug: "v1-0-1"}, | ||
}, | ||
}, | ||
{ | ||
name: "only latest minor combined with min release", | ||
params: Parameters{ | ||
MinRelease: "v0.1.2", | ||
OnlyLatestMinor: true, | ||
}, | ||
releases: []Release{ | ||
{Name: "v0.0.0"}, | ||
{Name: "v0.0.1"}, | ||
{Name: "v0.1.0"}, | ||
{Name: "v0.1.1"}, | ||
{Name: "v1.0.0"}, | ||
{Name: "v1.0.1"}, | ||
}, | ||
expectedReleases: []Release{ | ||
{Name: "v1.0.1", NameSlug: "v1-0-1"}, | ||
}, | ||
}, | ||
{ | ||
name: "keep releases returns only the amount of releases we want to keep", | ||
params: Parameters{ | ||
MinRelease: "v0.1.2", | ||
KeepReleases: 2, | ||
}, | ||
releases: []Release{ | ||
{Name: "v0.0.0"}, | ||
{Name: "v0.0.1"}, | ||
{Name: "v0.1.0"}, | ||
{Name: "v0.1.1"}, | ||
{Name: "v1.0.0"}, | ||
{Name: "v1.0.1"}, | ||
}, | ||
expectedReleases: []Release{ | ||
{Name: "v1.0.0", NameSlug: "v1-0-0"}, | ||
{Name: "v1.0.1", NameSlug: "v1-0-1"}, | ||
}, | ||
}, | ||
{ | ||
name: "keep releases plus only latest minor returns right releases", | ||
params: Parameters{ | ||
MinRelease: "v0.1.0", | ||
KeepReleases: 1, | ||
OnlyLatestMinor: true, | ||
}, | ||
releases: []Release{ | ||
{Name: "v0.0.0"}, | ||
{Name: "v0.0.1"}, | ||
{Name: "v0.1.0"}, | ||
{Name: "v0.1.1"}, | ||
{Name: "v1.0.0"}, | ||
{Name: "v1.0.1"}, | ||
}, | ||
expectedReleases: []Release{ | ||
{Name: "v1.0.1", NameSlug: "v1-0-1"}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range cases { | ||
t.Run(test.name, func(t *testing.T) { | ||
releases, err := getFilteredReleases(test.releases, test.params) | ||
if err != nil { | ||
t.Errorf("unexpected error: %v", err) | ||
} | ||
|
||
if !reflect.DeepEqual(releases, test.expectedReleases) { | ||
t.Errorf("expected releases to be %v, got %v", test.expectedReleases, releases) | ||
} | ||
}) | ||
} | ||
} |