etcdenvironment: order map keys consistently

This commit is contained in:
Jonathan Boulle 2014-06-23 15:13:11 -07:00
parent 8eb0636034
commit 338e1b64ab
2 changed files with 10 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package initialize
import ( import (
"errors" "errors"
"fmt" "fmt"
"sort"
"github.com/coreos/coreos-cloudinit/system" "github.com/coreos/coreos-cloudinit/system"
) )
@ -19,9 +20,16 @@ func (ee EtcdEnvironment) String() (out string) {
} }
} }
var sorted sort.StringSlice
for k, _ := range norm {
sorted = append(sorted, k)
}
sorted.Sort()
out += "[Service]\n" out += "[Service]\n"
for key, val := range norm { for _, key := range sorted {
val := norm[key]
out += fmt.Sprintf("Environment=\"ETCD_%s=%s\"\n", key, val) out += fmt.Sprintf("Environment=\"ETCD_%s=%s\"\n", key, val)
} }

View File

@ -102,8 +102,8 @@ func TestEtcdEnvironmentWrittenToDisk(t *testing.T) {
} }
expect := `[Service] expect := `[Service]
Environment="ETCD_NAME=node001"
Environment="ETCD_DISCOVERY=http://disco.example.com/foobar" Environment="ETCD_DISCOVERY=http://disco.example.com/foobar"
Environment="ETCD_NAME=node001"
Environment="ETCD_PEER_BIND_ADDR=127.0.0.1:7002" Environment="ETCD_PEER_BIND_ADDR=127.0.0.1:7002"
` `
if string(contents) != expect { if string(contents) != expect {