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>
This commit is contained in:
Sebastiaan van Stijn 2023-06-12 18:20:38 +02:00
parent f4bde68694
commit d68b361538
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
2 changed files with 4 additions and 9 deletions

View File

@ -133,7 +133,7 @@ func Service(
Hosts: convertExtraHosts(service.ExtraHosts),
DNSConfig: dnsConfig,
Healthcheck: healthcheck,
Env: sortStrings(convertEnvironment(service.Environment)),
Env: convertEnvironment(service.Environment),
Labels: AddStackLabel(namespace, service.Labels),
Dir: service.WorkingDir,
User: service.User,
@ -199,11 +199,6 @@ func getPlacementPreference(preferences []composetypes.PlacementPreferences) []s
return result
}
func sortStrings(strs []string) []string {
sort.Strings(strs)
return strs
}
func convertServiceNetworks(
networks map[string]*composetypes.ServiceNetworkConfig,
networkConfigs networkMap,
@ -596,6 +591,8 @@ func convertEndpointSpec(endpointMode string, source []composetypes.ServicePortC
}
}
// convertEnvironment converts key/value mappings to a slice, and sorts
// the results.
func convertEnvironment(source map[string]*string) []string {
var output []string
@ -607,7 +604,7 @@ func convertEnvironment(source map[string]*string) []string {
output = append(output, name+"="+*value)
}
}
sort.Strings(output)
return output
}

View File

@ -3,7 +3,6 @@ package convert
import (
"context"
"os"
"sort"
"strings"
"testing"
"time"
@ -59,7 +58,6 @@ func TestConvertEnvironment(t *testing.T) {
"key": strPtr("value"),
}
env := convertEnvironment(source)
sort.Strings(env)
assert.Check(t, is.DeepEqual([]string{"foo=bar", "key=value"}, env))
}