mirror of
https://github.com/containers/podman.git
synced 2025-06-22 01:48:54 +08:00
network ls: show networks in deterministic order
The new network backend stores the networks in a map so the returned order is not deterministic. Lets sort the network names alphabetically to ensure a deterministic order. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
@ -3,6 +3,7 @@ package network
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/containers/common/pkg/completion"
|
||||
@ -73,6 +74,11 @@ func networkList(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// sort the networks to make sure the order is deterministic
|
||||
sort.Slice(responses, func(i, j int) bool {
|
||||
return responses[i].Name < responses[j].Name
|
||||
})
|
||||
|
||||
switch {
|
||||
// quiet means we only print the network names
|
||||
case networkListOptions.Quiet:
|
||||
|
@ -16,6 +16,21 @@ load helpers
|
||||
if [[ ${output} = ${heading} ]]; then
|
||||
die "network ls --noheading did not remove heading: $output"
|
||||
fi
|
||||
|
||||
# check deterministic list order
|
||||
local net1=a-$(random_string 10)
|
||||
local net2=b-$(random_string 10)
|
||||
local net3=c-$(random_string 10)
|
||||
run_podman network create $net1
|
||||
run_podman network create $net2
|
||||
run_podman network create $net3
|
||||
|
||||
run_podman network ls --quiet
|
||||
# just check the the order of the created networks is correct
|
||||
# we cannot do an exact match since developer and CI systems could contain more networks
|
||||
is "$output" ".*$net1.*$net2.*$net3.*podman.*" "networks sorted alphabetically"
|
||||
|
||||
run_podman network rm $net1 $net2 $net3
|
||||
}
|
||||
|
||||
# Copied from tsweeney's https://github.com/containers/podman/issues/4827
|
||||
|
Reference in New Issue
Block a user