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

View File

@ -536,9 +536,6 @@ func loadFileObjectConfig(name string, objType string, obj types.FileObjectConfi
} }
// if not "external: true" // if not "external: true"
} else { } 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) obj.File = absPath(details.WorkingDir, obj.File)
} }

View File

@ -214,26 +214,6 @@ configs:
require.Len(t, actual.Configs, 1) 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) { func TestParseAndLoad(t *testing.T) {
actual, err := loadYAML(sampleYAML) actual, err := loadYAML(sampleYAML)
require.NoError(t, err) require.NoError(t, err)
@ -1484,11 +1464,24 @@ services:
image: busybox image: busybox
isolation: process isolation: process
configs: configs:
super: foo:
name: fooqux
external: true 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.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) assert.Equal(t, "process", actual.Services[0].Isolation)
} }
@ -1535,8 +1528,8 @@ func TestLoadSecretsWarnOnDeprecatedExternalNameVersion35(t *testing.T) {
}, },
}, },
} }
details := types.ConfigDetails{ details := types.ConfigDetails{
Version: "3.5", Version: "3.5",
} }
secrets, err := LoadSecrets(source, details) secrets, err := LoadSecrets(source, details)
require.NoError(t, err) 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) { func TestValidateSecretConfigNames(t *testing.T) {
config := dict{ config := dict{
"version": "3.5", "version": "3.5",
"configs": dict{ "configs": dict{
"bar": dict{ "bar": dict{
"name": "foobar", "name": "foobar",
}, },
}, },
"secrets": dict{ "secrets": dict{
"baz": dict{ "baz": dict{
"name": "foobaz", "name": "foobaz",
}, },
}, },
} }
err := Validate(config, "3.5") 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 // FileObjectConfig is a config type for a file used by a service
type FileObjectConfig struct { type FileObjectConfig struct {
Name string Name string
File string File string
External External External External
Labels Labels Labels Labels