mirror of https://github.com/docker/cli.git
77 lines
1.3 KiB
Go
77 lines
1.3 KiB
Go
package schema
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
type dict map[string]interface{}
|
|
|
|
func TestValidate(t *testing.T) {
|
|
config := dict{
|
|
"version": "3.0",
|
|
"services": dict{
|
|
"foo": dict{
|
|
"image": "busybox",
|
|
},
|
|
},
|
|
}
|
|
|
|
assert.NoError(t, Validate(config, "3.0"))
|
|
}
|
|
|
|
func TestValidateUndefinedTopLevelOption(t *testing.T) {
|
|
config := dict{
|
|
"version": "3.0",
|
|
"helicopters": dict{
|
|
"foo": dict{
|
|
"image": "busybox",
|
|
},
|
|
},
|
|
}
|
|
|
|
err := Validate(config, "3.0")
|
|
assert.Error(t, err)
|
|
assert.Contains(t, err.Error(), "Additional property helicopters is not allowed")
|
|
}
|
|
|
|
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")
|
|
}
|
|
|
|
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"))
|
|
}
|