Remove duplication for secrets / configs, combine 3.5 loader tests, remove extraneous error call, regenerate schema correctly

Signed-off-by: Ilya Sotkov <ilya@sotkov.com>
This commit is contained in:
Ilya Sotkov 2017-11-11 07:11:29 +02:00
parent 1f10b31017
commit ec47003ecb
6 changed files with 41 additions and 76 deletions

View File

@ -101,12 +101,6 @@ func Secrets(namespace Namespace, secrets map[string]composetypes.SecretConfig)
continue
}
if secret.Name != "" {
name = secret.Name
} else {
name = namespace.Scope(name)
}
obj, err := fileObjectConfig(namespace, name, composetypes.FileObjectConfig(secret))
if err != nil {
return nil, err
@ -124,12 +118,6 @@ func Configs(namespace Namespace, configs map[string]composetypes.ConfigObjConfi
continue
}
if config.Name != "" {
name = config.Name
} else {
name = namespace.Scope(name)
}
obj, err := fileObjectConfig(namespace, name, composetypes.FileObjectConfig(config))
if err != nil {
return nil, err
@ -150,6 +138,12 @@ func fileObjectConfig(namespace Namespace, name string, obj composetypes.FileObj
return swarmFileObject{}, err
}
if obj.Name != "" {
name = obj.Name
} else {
name = namespace.Scope(name)
}
return swarmFileObject{
Annotations: swarm.Annotations{
Name: name,

View File

@ -536,9 +536,6 @@ func loadFileObjectConfig(name string, objType string, obj types.FileObjectConfi
}
// if not "external: true"
} else {
if obj.File == "" {
return obj, errors.Errorf("%[1]s %[2]s: specify a file or \"external: true\"", objType, name)
}
obj.File = absPath(details.WorkingDir, obj.File)
}

View File

@ -214,26 +214,6 @@ configs:
require.Len(t, actual.Configs, 1)
}
func TestLoadV35(t *testing.T) {
actual, err := loadYAML(`
version: "3.5"
services:
foo:
image: busybox
secrets: [foo, bar, baz]
secrets:
foo:
name: fooqux
external: true
bar:
name: barqux
file: ./full-example.yml
`)
require.NoError(t, err)
assert.Len(t, actual.Services, 1)
assert.Len(t, actual.Secrets, 2)
}
func TestParseAndLoad(t *testing.T) {
actual, err := loadYAML(sampleYAML)
require.NoError(t, err)
@ -1484,11 +1464,24 @@ services:
image: busybox
isolation: process
configs:
super:
foo:
name: fooqux
external: true
bar:
name: barqux
file: ./example1.env
secrets:
foo:
name: fooqux
external: true
bar:
name: barqux
file: ./full-example.yml
`)
require.NoError(t, err)
require.Len(t, actual.Services, 1)
assert.Len(t, actual.Services, 1)
assert.Len(t, actual.Secrets, 2)
assert.Len(t, actual.Configs, 2)
assert.Equal(t, "process", actual.Services[0].Isolation)
}
@ -1535,8 +1528,8 @@ func TestLoadSecretsWarnOnDeprecatedExternalNameVersion35(t *testing.T) {
},
},
}
details := types.ConfigDetails{
Version: "3.5",
details := types.ConfigDetails{
Version: "3.5",
}
secrets, err := LoadSecrets(source, details)
require.NoError(t, err)

File diff suppressed because one or more lines are too long

View File

@ -48,17 +48,17 @@ func TestValidateAllowsXTopLevelFields(t *testing.T) {
func TestValidateSecretConfigNames(t *testing.T) {
config := dict{
"version": "3.5",
"version": "3.5",
"configs": dict{
"bar": dict{
"name": "foobar",
},
},
"secrets": dict{
"baz": dict{
"name": "foobaz",
},
},
"bar": dict{
"name": "foobar",
},
},
"secrets": dict{
"baz": dict{
"name": "foobaz",
},
},
}
err := Validate(config, "3.5")

View File

@ -348,7 +348,7 @@ type CredentialSpecConfig struct {
// FileObjectConfig is a config type for a file used by a service
type FileObjectConfig struct {
Name string
Name string
File string
External External
Labels Labels