Merge pull request #155 from jonboulle/etcd

etcdenvironment: order map keys consistently
This commit is contained in:
Jonathan Boulle 2014-06-24 15:02:04 -07:00
commit 29a7b0e34f
2 changed files with 10 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package initialize
import (
"errors"
"fmt"
"sort"
"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"
for key, val := range norm {
for _, key := range sorted {
val := norm[key]
out += fmt.Sprintf("Environment=\"ETCD_%s=%s\"\n", key, val)
}

View File

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