2016-12-20 16:26:49 -05:00
|
|
|
package schema
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
type dict map[string]interface{}
|
|
|
|
|
2017-01-10 17:10:53 -05:00
|
|
|
func TestValidate(t *testing.T) {
|
2016-12-20 16:26:49 -05:00
|
|
|
config := dict{
|
2017-01-10 17:10:53 -05:00
|
|
|
"version": "3.0",
|
2016-12-20 16:26:49 -05:00
|
|
|
"services": dict{
|
|
|
|
"foo": dict{
|
|
|
|
"image": "busybox",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-01-10 17:10:53 -05:00
|
|
|
assert.NoError(t, Validate(config, "3.0"))
|
2016-12-20 16:26:49 -05:00
|
|
|
}
|
|
|
|
|
2017-01-10 17:10:53 -05:00
|
|
|
func TestValidateUndefinedTopLevelOption(t *testing.T) {
|
2016-12-20 16:26:49 -05:00
|
|
|
config := dict{
|
2017-01-10 17:10:53 -05:00
|
|
|
"version": "3.0",
|
2016-12-20 16:26:49 -05:00
|
|
|
"helicopters": dict{
|
|
|
|
"foo": dict{
|
|
|
|
"image": "busybox",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-01-10 17:10:53 -05:00
|
|
|
err := Validate(config, "3.0")
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Contains(t, err.Error(), "Additional property helicopters is not allowed")
|
|
|
|
}
|
|
|
|
|
2017-08-17 12:56:33 -04:00
|
|
|
func TestValidateAllowsXTopLevelFields(t *testing.T) {
|
|
|
|
config := dict{
|
|
|
|
"version": "3.4",
|
|
|
|
"x-extra-stuff": dict{},
|
|
|
|
}
|
|
|
|
|
|
|
|
err := Validate(config, "3.4")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
2017-11-10 08:35:29 -05:00
|
|
|
func TestValidateSecretConfigNames(t *testing.T) {
|
|
|
|
config := dict{
|
2017-11-11 00:11:29 -05:00
|
|
|
"version": "3.5",
|
2017-11-10 08:35:29 -05:00
|
|
|
"configs": dict{
|
2017-11-11 00:11:29 -05:00
|
|
|
"bar": dict{
|
|
|
|
"name": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"secrets": dict{
|
|
|
|
"baz": dict{
|
|
|
|
"name": "foobaz",
|
|
|
|
},
|
|
|
|
},
|
2017-11-10 08:35:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
err := Validate(config, "3.5")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
2017-01-10 17:10:53 -05:00
|
|
|
func TestValidateInvalidVersion(t *testing.T) {
|
|
|
|
config := dict{
|
|
|
|
"version": "2.1",
|
|
|
|
"services": dict{
|
|
|
|
"foo": dict{
|
|
|
|
"image": "busybox",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
err := Validate(config, "2.1")
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Contains(t, err.Error(), "unsupported Compose file version: 2.1")
|
2016-12-20 16:26:49 -05:00
|
|
|
}
|
2017-05-06 09:49:42 -04:00
|
|
|
|
|
|
|
type array []interface{}
|
|
|
|
|
|
|
|
func TestValidatePlacement(t *testing.T) {
|
|
|
|
config := dict{
|
|
|
|
"version": "3.3",
|
|
|
|
"services": dict{
|
|
|
|
"foo": dict{
|
|
|
|
"image": "busybox",
|
|
|
|
"deploy": dict{
|
|
|
|
"placement": dict{
|
|
|
|
"preferences": array{
|
|
|
|
dict{
|
|
|
|
"spread": "node.labels.az",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.NoError(t, Validate(config, "3.3"))
|
|
|
|
}
|
2017-11-17 09:31:13 -05:00
|
|
|
|
|
|
|
func TestValidateIsolation(t *testing.T) {
|
|
|
|
config := dict{
|
|
|
|
"version": "3.5",
|
|
|
|
"services": dict{
|
|
|
|
"foo": dict{
|
|
|
|
"image": "busybox",
|
|
|
|
"isolation": "some-isolation-value",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
assert.NoError(t, Validate(config, "3.5"))
|
|
|
|
}
|