From 3b980bd9dcfe4551ae417f99dc3015eadb193347 Mon Sep 17 00:00:00 2001 From: Daniel Smith Date: Mon, 16 Jun 2014 20:05:22 -0700 Subject: [PATCH] Make deterministic --- pkg/labels/labels.go | 3 +++ pkg/labels/labels_test.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/labels/labels.go b/pkg/labels/labels.go index 38ec2ac0e94..86971d3f841 100644 --- a/pkg/labels/labels.go +++ b/pkg/labels/labels.go @@ -17,6 +17,7 @@ limitations under the License. package labels import ( + "sort" "strings" ) @@ -35,6 +36,8 @@ func (ls Set) String() string { for key, value := range ls { query = append(query, key+"="+value) } + // Sort for determinism. + sort.StringSlice(query).Sort() return strings.Join(query, ",") } diff --git a/pkg/labels/labels_test.go b/pkg/labels/labels_test.go index 76db00b951a..74db659acaa 100644 --- a/pkg/labels/labels_test.go +++ b/pkg/labels/labels_test.go @@ -29,7 +29,7 @@ func matches(t *testing.T, ls Set, want string) { func TestSetString(t *testing.T) { matches(t, Set{"x": "y"}, "x=y") matches(t, Set{"foo": "bar"}, "foo=bar") - matches(t, Set{"foo": "bar", "baz": "qup"}, "foo=bar,baz=qup") + matches(t, Set{"foo": "bar", "baz": "qup"}, "baz=qup,foo=bar") // TODO: Make our label representation robust enough to handel labels // with ",=!" characters in their names.