forked from pion/dtls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alert_test.go
48 lines (44 loc) · 1.17 KB
/
alert_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
39
40
41
42
43
44
45
46
47
48
package dtls
import (
"reflect"
"testing"
)
func TestAlert(t *testing.T) {
for _, test := range []struct {
Name string
Data []byte
Want *alert
WantUnmarshalError error
}{
{
Name: "Valid Alert",
Data: []byte{0x02, 0x0A},
Want: &alert{
alertLevel: alertLevelFatal,
alertDescription: alertUnexpectedMessage,
},
},
{
Name: "Invalid alert length",
Data: []byte{0x00},
Want: &alert{},
WantUnmarshalError: errBufferTooSmall,
},
} {
a := &alert{}
if err := a.Unmarshal(test.Data); err != test.WantUnmarshalError {
t.Errorf("Unexpected Error %v: exp: %v got: %v", test.Name, test.WantUnmarshalError, err)
} else if !reflect.DeepEqual(test.Want, a) {
t.Errorf("%q alert.unmarshal: got %v, want %v", test.Name, a, test.Want)
}
if test.WantUnmarshalError != nil {
return
}
data, marshalErr := a.Marshal()
if marshalErr != nil {
t.Errorf("Unexpected Error %v: got: %v", test.Name, marshalErr)
} else if !reflect.DeepEqual(test.Data, data) {
t.Errorf("%q alert.marshal: got % 02x, want % 02x", test.Name, data, test.Data)
}
}
}