From e982f976ebed09e113d4cecafbe9ddbc3cf98d4d Mon Sep 17 00:00:00 2001 From: James Phillips Date: Wed, 14 Oct 2015 13:41:04 -0700 Subject: [PATCH] Adds unit tests for new structs clone functions. --- consul/structs/structs_test.go | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/consul/structs/structs_test.go b/consul/structs/structs_test.go index 4a2215cf8..85a9c0eb4 100644 --- a/consul/structs/structs_test.go +++ b/consul/structs/structs_test.go @@ -53,3 +53,53 @@ func TestStructs_Implements(t *testing.T) { _ CompoundResponse = &KeyringResponses{} ) } + +func TestStructs_ServiceNode_Clone(t *testing.T) { + sn := &ServiceNode{ + Node: "node1", + Address: "127.0.0.1", + ServiceID: "service1", + ServiceName: "dogs", + ServiceTags: []string{"prod", "v1"}, + ServiceAddress: "127.0.0.2", + ServicePort: 8080, + RaftIndex: RaftIndex{ + CreateIndex: 1, + ModifyIndex: 2, + }, + } + + clone := sn.Clone() + if !reflect.DeepEqual(sn, clone) { + t.Fatalf("bad: %v", clone) + } + + sn.ServiceTags = append(sn.ServiceTags, "hello") + if reflect.DeepEqual(sn, clone) { + t.Fatalf("clone wasn't independent of the original") + } +} + +func TestStructs_DirEntry_Clone(t *testing.T) { + e := &DirEntry{ + LockIndex: 5, + Key: "hello", + Flags: 23, + Value: []byte("this is a test"), + Session: "session1", + RaftIndex: RaftIndex{ + CreateIndex: 1, + ModifyIndex: 2, + }, + } + + clone := e.Clone() + if !reflect.DeepEqual(e, clone) { + t.Fatalf("bad: %v", clone) + } + + e.Value = []byte("a new value") + if reflect.DeepEqual(e, clone) { + t.Fatalf("clone wasn't independent of the original") + } +}