Adds unit tests for new structs clone functions.

This commit is contained in:
James Phillips 2015-10-14 13:41:04 -07:00
parent 46be9fa2cf
commit e982f976eb
1 changed files with 50 additions and 0 deletions

View File

@ -53,3 +53,53 @@ func TestStructs_Implements(t *testing.T) {
_ CompoundResponse = &KeyringResponses{} _ 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")
}
}