2017-12-17 19:14:21 +02:00
|
|
|
package artifact
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"golang.org/x/sync/errgroup"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAdd(t *testing.T) {
|
|
|
|
var g errgroup.Group
|
|
|
|
var artifacts = New()
|
|
|
|
for _, a := range []Artifact{
|
|
|
|
{
|
|
|
|
Name: "foo",
|
2017-12-17 20:31:06 +02:00
|
|
|
Type: UploadableArchive,
|
2017-12-17 19:14:21 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "bar",
|
|
|
|
Type: Binary,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "foobar",
|
|
|
|
Type: DockerImage,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "check",
|
|
|
|
Type: Checksum,
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
a := a
|
|
|
|
g.Go(func() error {
|
|
|
|
artifacts.Add(a)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
assert.NoError(t, g.Wait())
|
2017-12-17 19:50:09 +02:00
|
|
|
assert.Len(t, artifacts.List(), 4)
|
2017-12-17 19:14:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFilter(t *testing.T) {
|
|
|
|
var data = []Artifact{
|
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
Goos: "linux",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "bar",
|
|
|
|
Goarch: "amd64",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "foobar",
|
|
|
|
Goarm: "6",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "check",
|
|
|
|
Type: Checksum,
|
|
|
|
},
|
2017-12-17 20:31:06 +02:00
|
|
|
{
|
|
|
|
Name: "checkzumm",
|
|
|
|
Type: Checksum,
|
|
|
|
},
|
2017-12-17 19:14:21 +02:00
|
|
|
}
|
|
|
|
var artifacts = New()
|
|
|
|
for _, a := range data {
|
|
|
|
artifacts.Add(a)
|
|
|
|
}
|
2017-12-17 20:31:06 +02:00
|
|
|
|
2017-12-17 19:14:21 +02:00
|
|
|
assert.Len(t, artifacts.Filter(ByGoos("linux")).items, 1)
|
|
|
|
assert.Len(t, artifacts.Filter(ByGoos("darwin")).items, 0)
|
|
|
|
|
|
|
|
assert.Len(t, artifacts.Filter(ByGoarch("amd64")).items, 1)
|
|
|
|
assert.Len(t, artifacts.Filter(ByGoarch("386")).items, 0)
|
|
|
|
|
|
|
|
assert.Len(t, artifacts.Filter(ByGoarm("6")).items, 1)
|
|
|
|
assert.Len(t, artifacts.Filter(ByGoarm("7")).items, 0)
|
|
|
|
|
2017-12-17 20:31:06 +02:00
|
|
|
assert.Len(t, artifacts.Filter(ByType(Checksum)).items, 2)
|
2017-12-17 19:14:21 +02:00
|
|
|
assert.Len(t, artifacts.Filter(ByType(Binary)).items, 0)
|
2017-12-17 20:31:06 +02:00
|
|
|
|
|
|
|
assert.Len(t, artifacts.Filter(ByType(Checksum), func(a Artifact) bool {
|
|
|
|
return a.Name == "checkzumm"
|
|
|
|
}).List(), 1)
|
2017-12-17 19:14:21 +02:00
|
|
|
}
|
2017-12-17 19:50:09 +02:00
|
|
|
|
|
|
|
func TestGroupByPlatform(t *testing.T) {
|
|
|
|
var data = []Artifact{
|
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
Goos: "linux",
|
|
|
|
Goarch: "amd64",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "bar",
|
|
|
|
Goos: "linux",
|
|
|
|
Goarch: "amd64",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "foobar",
|
|
|
|
Goos: "linux",
|
|
|
|
Goarch: "arm",
|
|
|
|
Goarm: "6",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "check",
|
|
|
|
Type: Checksum,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
var artifacts = New()
|
|
|
|
for _, a := range data {
|
|
|
|
artifacts.Add(a)
|
|
|
|
}
|
|
|
|
|
|
|
|
var groups = artifacts.GroupByPlatform()
|
|
|
|
assert.Len(t, groups["linuxamd64"], 2)
|
|
|
|
assert.Len(t, groups["linuxarm6"], 1)
|
|
|
|
}
|