Merge pull request #30781 from AkihiroSuda/fix-stack-env

compose: fix environment interpolation from the client
This commit is contained in:
Vincent Demeester
2017-03-17 15:56:50 +01:00
committed by GitHub
9 changed files with 177 additions and 106 deletions

View File

@ -394,11 +394,16 @@ func convertEndpointSpec(endpointMode string, source []composetypes.ServicePortC
}, nil
}
func convertEnvironment(source map[string]string) []string {
func convertEnvironment(source map[string]*string) []string {
var output []string
for name, value := range source {
output = append(output, fmt.Sprintf("%s=%s", name, value))
switch value {
case nil:
output = append(output, name)
default:
output = append(output, fmt.Sprintf("%s=%s", name, *value))
}
}
return output

View File

@ -43,10 +43,14 @@ func TestConvertRestartPolicyFromFailure(t *testing.T) {
assert.DeepEqual(t, policy, expected)
}
func strPtr(val string) *string {
return &val
}
func TestConvertEnvironment(t *testing.T) {
source := map[string]string{
"foo": "bar",
"key": "value",
source := map[string]*string{
"foo": strPtr("bar"),
"key": strPtr("value"),
}
env := convertEnvironment(source)
sort.Strings(env)