mirror of https://github.com/status-im/consul.git
Adds unit tests for new structs clone functions.
This commit is contained in:
parent
a1cb9b8e62
commit
ef5233165b
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue