1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-11 14:39:28 +02:00

test: group by id

This commit is contained in:
Carlos A Becker 2022-01-23 23:49:40 -03:00
parent aad1e1e3d5
commit 45c0e2bcaf
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
2 changed files with 56 additions and 0 deletions

View File

@ -256,6 +256,10 @@ func (artifacts Artifacts) List() []*Artifact {
func (artifacts Artifacts) GroupByID() map[string][]*Artifact {
result := map[string][]*Artifact{}
for _, a := range artifacts.items {
id := a.ID()
if id == "" {
continue
}
result[a.ID()] = append(result[a.ID()], a)
}
return result

View File

@ -181,6 +181,58 @@ func TestRemove(t *testing.T) {
})
}
func TestGroupByID(t *testing.T) {
data := []*Artifact{
{
Name: "foo",
Extra: map[string]interface{}{
ExtraID: "foo",
},
},
{
Name: "bar",
Extra: map[string]interface{}{
ExtraID: "foo",
},
},
{
Name: "foobar",
Goos: "linux",
Extra: map[string]interface{}{
ExtraID: "foovar",
},
},
{
Name: "foobar",
Goos: "linux",
Extra: map[string]interface{}{
ExtraID: "foovar",
},
},
{
Name: "foobar",
Goos: "linux",
Extra: map[string]interface{}{
ExtraID: "foobar",
},
},
{
Name: "check",
Type: Checksum,
},
}
artifacts := New()
for _, a := range data {
artifacts.Add(a)
}
groups := artifacts.GroupByID()
require.Len(t, groups["foo"], 2)
require.Len(t, groups["foobar"], 1)
require.Len(t, groups["foovar"], 2)
require.Len(t, groups, 3)
}
func TestGroupByPlatform(t *testing.T) {
data := []*Artifact{
{