-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparcel_test.go
38 lines (35 loc) · 1.72 KB
/
parcel_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package p2p
import "testing"
func TestParcel_Test(t *testing.T) {
//&Parcel{Type: 0, Address: "", Payload: []byte{}},
tests := []struct {
name string
p *Parcel
wantErr bool
app bool
}{
{"blank parcel", &Parcel{}, true, false},
{"heartbeat", &Parcel{ptype: TypeHeartbeat, Address: "", Payload: []byte{0}}, false, false},
{"empty payload", &Parcel{ptype: TypeHeartbeat, Address: "", Payload: []byte{}}, true, false},
{"ping", &Parcel{ptype: TypePing, Address: "", Payload: []byte{0}}, false, false},
{"pong", &Parcel{ptype: TypePong, Address: "", Payload: []byte{0}}, false, false},
{"p request", &Parcel{ptype: TypePeerRequest, Address: "", Payload: []byte{0}}, false, false},
{"p response", &Parcel{ptype: TypePeerResponse, Address: "", Payload: []byte{0}}, false, false},
{"alert", &Parcel{ptype: TypeAlert, Address: "", Payload: []byte{0}}, false, false},
{"message", &Parcel{ptype: TypeMessage, Address: "", Payload: []byte{0}}, false, true},
{"messagepart", &Parcel{ptype: TypeMessagePart, Address: "", Payload: []byte{0}}, false, true},
{"handshake", &Parcel{ptype: TypeHandshake, Address: "", Payload: []byte{0}}, false, false},
{"reject alternative", &Parcel{ptype: TypeRejectAlternative, Address: "", Payload: []byte{0}}, false, false},
{"out of range", &Parcel{ptype: ParcelType(len(typeStrings)), Address: "", Payload: []byte{0}}, true, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := tt.p.Valid(); (err != nil) != tt.wantErr {
t.Errorf("Parcel.Valid() error = %v, wantErr %v", err, tt.wantErr)
}
if isapp := tt.p.IsApplicationMessage(); isapp != tt.app {
t.Errorf("Parcel.IsApplicationMessage() = %v, app = %v", isapp, tt.app)
}
})
}
}