mirror of https://github.com/docker/cli.git
cli/compose/schema: Validate(): normalize version before validating
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
cf8c4bab64
commit
d44eca129f
|
@ -50,6 +50,8 @@ func Version(config map[string]interface{}) string {
|
|||
|
||||
func normalizeVersion(version string) string {
|
||||
switch version {
|
||||
case "":
|
||||
return defaultVersion
|
||||
case "3":
|
||||
return "3.0"
|
||||
default:
|
||||
|
@ -62,6 +64,7 @@ var schemas embed.FS
|
|||
|
||||
// Validate uses the jsonschema to validate the configuration
|
||||
func Validate(config map[string]interface{}, version string) error {
|
||||
version = normalizeVersion(version)
|
||||
schemaData, err := schemas.ReadFile("data/config_schema_v" + version + ".json")
|
||||
if err != nil {
|
||||
return errors.Errorf("unsupported Compose file version: %s", version)
|
||||
|
|
|
@ -20,6 +20,9 @@ func TestValidate(t *testing.T) {
|
|||
}
|
||||
|
||||
assert.NilError(t, Validate(config, "3.0"))
|
||||
assert.NilError(t, Validate(config, "3"))
|
||||
assert.ErrorContains(t, Validate(config, ""), "unsupported Compose file version: 1.0")
|
||||
assert.ErrorContains(t, Validate(config, "12345"), "unsupported Compose file version: 12345")
|
||||
}
|
||||
|
||||
func TestValidateUndefinedTopLevelOption(t *testing.T) {
|
||||
|
@ -84,6 +87,7 @@ func TestValidateCredentialSpecs(t *testing.T) {
|
|||
version string
|
||||
expectedErr string
|
||||
}{
|
||||
{version: "3", expectedErr: "credential_spec"},
|
||||
{version: "3.0", expectedErr: "credential_spec"},
|
||||
{version: "3.1", expectedErr: "credential_spec"},
|
||||
{version: "3.2", expectedErr: "credential_spec"},
|
||||
|
|
Loading…
Reference in New Issue