-
Notifications
You must be signed in to change notification settings - Fork 48
/
m_gact_test.go
53 lines (47 loc) · 1.15 KB
/
m_gact_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
49
50
51
52
53
package tc
import (
"errors"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestGact(t *testing.T) {
tests := map[string]struct {
val Gact
err1 error
err2 error
}{
"failing": {val: Gact{Tm: &Tcft{Install: 2}}, err1: ErrNoArgAlter},
"simple": {val: Gact{Parms: &GactParms{Index: 1, Capab: 2}, Prob: &GactProb{PType: 2}}},
}
for name, testcase := range tests {
t.Run(name, func(t *testing.T) {
data, err1 := marshalGact(&testcase.val)
if err1 != nil {
if errors.Is(testcase.err1, err1) {
return
}
t.Fatalf("Unexpected error: %v", err1)
}
newData, tm := injectTcft(t, data, tcaGactTm)
newData = injectAttribute(t, newData, []byte{}, tcaGactPad)
val := Gact{}
err2 := unmarshalGact(newData, &val)
if err2 != nil {
if errors.Is(testcase.err2, err2) {
return
}
t.Fatalf("Unexpected error: %v", err2)
}
testcase.val.Tm = tm
if diff := cmp.Diff(val, testcase.val); diff != "" {
t.Fatalf("Gact missmatch (want +got):\n%s", diff)
}
})
}
t.Run("nil", func(t *testing.T) {
_, err := marshalGact(nil)
if !errors.Is(err, ErrNoArg) {
t.Fatalf("unexpected error: %v", err)
}
})
}