2016-04-19 20:02:28 +00:00
|
|
|
package yaml
|
2015-04-16 07:10:17 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2015-09-30 01:21:17 +00:00
|
|
|
"github.com/franela/goblin"
|
2015-04-16 07:10:17 +00:00
|
|
|
)
|
|
|
|
|
2016-04-11 18:15:53 +00:00
|
|
|
func TestMatrix(t *testing.T) {
|
2015-04-16 07:10:17 +00:00
|
|
|
|
|
|
|
g := goblin.Goblin(t)
|
|
|
|
g.Describe("Calculate matrix", func() {
|
|
|
|
|
2016-04-11 18:15:53 +00:00
|
|
|
axis, _ := ParseMatrixString(fakeMatrix)
|
2015-04-16 07:10:17 +00:00
|
|
|
|
|
|
|
g.It("Should calculate permutations", func() {
|
|
|
|
g.Assert(len(axis)).Equal(24)
|
|
|
|
})
|
|
|
|
|
|
|
|
g.It("Should not duplicate permutations", func() {
|
|
|
|
set := map[string]bool{}
|
|
|
|
for _, perm := range axis {
|
|
|
|
set[perm.String()] = true
|
|
|
|
}
|
|
|
|
g.Assert(len(set)).Equal(24)
|
|
|
|
})
|
2015-09-30 01:21:17 +00:00
|
|
|
|
|
|
|
g.It("Should return nil if no matrix", func() {
|
2016-04-11 18:15:53 +00:00
|
|
|
axis, err := ParseMatrixString("")
|
2015-09-30 01:21:17 +00:00
|
|
|
g.Assert(err == nil).IsTrue()
|
|
|
|
g.Assert(axis == nil).IsTrue()
|
|
|
|
})
|
2016-04-27 21:46:01 +00:00
|
|
|
|
|
|
|
g.It("Should return included axis", func() {
|
|
|
|
axis, err := ParseMatrixString(fakeMatrixInclude)
|
|
|
|
g.Assert(err == nil).IsTrue()
|
|
|
|
g.Assert(len(axis)).Equal(2)
|
|
|
|
g.Assert(axis[0]["go_version"]).Equal("1.5")
|
|
|
|
g.Assert(axis[1]["go_version"]).Equal("1.6")
|
|
|
|
g.Assert(axis[0]["python_version"]).Equal("3.4")
|
|
|
|
g.Assert(axis[1]["python_version"]).Equal("3.4")
|
|
|
|
})
|
2015-04-16 07:10:17 +00:00
|
|
|
})
|
|
|
|
}
|
2015-09-30 01:21:17 +00:00
|
|
|
|
|
|
|
var fakeMatrix = `
|
|
|
|
matrix:
|
|
|
|
go_version:
|
|
|
|
- go1
|
|
|
|
- go1.2
|
|
|
|
python_version:
|
|
|
|
- 3.2
|
|
|
|
- 3.3
|
|
|
|
django_version:
|
|
|
|
- 1.7
|
|
|
|
- 1.7.1
|
|
|
|
- 1.7.2
|
|
|
|
redis_version:
|
|
|
|
- 2.6
|
|
|
|
- 2.8
|
|
|
|
`
|
2016-04-27 21:46:01 +00:00
|
|
|
|
|
|
|
var fakeMatrixInclude = `
|
|
|
|
matrix:
|
|
|
|
include:
|
|
|
|
- go_version: 1.5
|
|
|
|
python_version: 3.4
|
|
|
|
- go_version: 1.6
|
|
|
|
python_version: 3.4
|
|
|
|
`
|