Skip to content

Commit d68b361

Browse files
committed
cli/compose/convert: convertEnvironment: sort results
All users of this function sorted the results afterwards, so let's do it as part of the function itself. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent f4bde68 commit d68b361

2 files changed

Lines changed: 4 additions & 9 deletions

File tree

cli/compose/convert/service.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func Service(
133133
Hosts: convertExtraHosts(service.ExtraHosts),
134134
DNSConfig: dnsConfig,
135135
Healthcheck: healthcheck,
136-
Env: sortStrings(convertEnvironment(service.Environment)),
136+
Env: convertEnvironment(service.Environment),
137137
Labels: AddStackLabel(namespace, service.Labels),
138138
Dir: service.WorkingDir,
139139
User: service.User,
@@ -199,11 +199,6 @@ func getPlacementPreference(preferences []composetypes.PlacementPreferences) []s
199199
return result
200200
}
201201

202-
func sortStrings(strs []string) []string {
203-
sort.Strings(strs)
204-
return strs
205-
}
206-
207202
func convertServiceNetworks(
208203
networks map[string]*composetypes.ServiceNetworkConfig,
209204
networkConfigs networkMap,
@@ -596,6 +591,8 @@ func convertEndpointSpec(endpointMode string, source []composetypes.ServicePortC
596591
}
597592
}
598593

594+
// convertEnvironment converts key/value mappings to a slice, and sorts
595+
// the results.
599596
func convertEnvironment(source map[string]*string) []string {
600597
var output []string
601598

@@ -607,7 +604,7 @@ func convertEnvironment(source map[string]*string) []string {
607604
output = append(output, name+"="+*value)
608605
}
609606
}
610-
607+
sort.Strings(output)
611608
return output
612609
}
613610

cli/compose/convert/service_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package convert
33
import (
44
"context"
55
"os"
6-
"sort"
76
"strings"
87
"testing"
98
"time"
@@ -59,7 +58,6 @@ func TestConvertEnvironment(t *testing.T) {
5958
"key": strPtr("value"),
6059
}
6160
env := convertEnvironment(source)
62-
sort.Strings(env)
6361
assert.Check(t, is.DeepEqual([]string{"foo=bar", "key=value"}, env))
6462
}
6563

0 commit comments

Comments
 (0)