added yaml include capability
This commit is contained in:
parent
2b7f46de08
commit
a9863ab986
2 changed files with 36 additions and 0 deletions
|
@ -29,6 +29,12 @@ func (a Axis) String() string {
|
|||
|
||||
// ParseMatrix parses the Yaml matrix definition.
|
||||
func ParseMatrix(data []byte) ([]Axis, error) {
|
||||
|
||||
axis, err := parseMatrixList(data)
|
||||
if err == nil && len(axis) != 0 {
|
||||
return axis, nil
|
||||
}
|
||||
|
||||
matrix, err := parseMatrix(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -98,3 +104,14 @@ func parseMatrix(raw []byte) (Matrix, error) {
|
|||
err := yaml.Unmarshal(raw, &data)
|
||||
return data.Matrix, err
|
||||
}
|
||||
|
||||
func parseMatrixList(raw []byte) ([]Axis, error) {
|
||||
data := struct {
|
||||
Matrix struct {
|
||||
Include []Axis
|
||||
}
|
||||
}{}
|
||||
|
||||
err := yaml.Unmarshal(raw, &data)
|
||||
return data.Matrix.Include, err
|
||||
}
|
||||
|
|
|
@ -30,6 +30,16 @@ func TestMatrix(t *testing.T) {
|
|||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(axis == nil).IsTrue()
|
||||
})
|
||||
|
||||
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")
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -49,3 +59,12 @@ matrix:
|
|||
- 2.6
|
||||
- 2.8
|
||||
`
|
||||
|
||||
var fakeMatrixInclude = `
|
||||
matrix:
|
||||
include:
|
||||
- go_version: 1.5
|
||||
python_version: 3.4
|
||||
- go_version: 1.6
|
||||
python_version: 3.4
|
||||
`
|
||||
|
|
Loading…
Reference in a new issue