From 338e1b64ab6d1b792be6fd94d73e833f7719c924 Mon Sep 17 00:00:00 2001 From: Jonathan Boulle Date: Mon, 23 Jun 2014 15:13:11 -0700 Subject: [PATCH] etcdenvironment: order map keys consistently --- initialize/etcd.go | 10 +++++++++- initialize/etcd_test.go | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/initialize/etcd.go b/initialize/etcd.go index 2f922b6..94186e8 100644 --- a/initialize/etcd.go +++ b/initialize/etcd.go @@ -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) } diff --git a/initialize/etcd_test.go b/initialize/etcd_test.go index 62fca6b..101cd68 100644 --- a/initialize/etcd_test.go +++ b/initialize/etcd_test.go @@ -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 {