Skip to content

Commit

Permalink
Adds unit tests for new structs clone functions.
Browse files Browse the repository at this point in the history
James Phillips committed Oct 15, 2015
1 parent a1cb9b8 commit ef52331
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions consul/structs/structs_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
}

0 comments on commit ef52331

Please sign in to comment.