...
1 package client
2
3 import (
4 "testing"
5
6 linstor "github.com/LINBIT/golinstor"
7 )
8
9 func TestRcIs(t *testing.T) {
10 cases := []struct {
11 descr string
12 rc int64
13 mask uint64
14 expectIs bool
15 }{{
16 descr: "exact match",
17 rc: -4611686018406153244,
18 mask: linstor.FailNotEnoughNodes,
19 expectIs: true,
20 }, {
21 descr: "wrong value",
22 rc: -4611686018406153244,
23 mask: linstor.FailInvldNodeName,
24 expectIs: false,
25 }}
26
27 for _, c := range cases {
28 r := ApiCallRc{RetCode: c.rc}
29
30 is := r.Is(c.mask)
31
32 if is && !c.expectIs {
33 t.Errorf("Case \"%s\": mask unexpectedly matches", c.descr)
34 t.Errorf("RetCode: %064b", uint64(c.rc))
35 t.Errorf("Mask: %064b", c.mask)
36 t.Errorf("And: %064b", uint64(c.rc)&c.mask)
37 }
38 if !is && c.expectIs {
39 t.Errorf("Case \"%s\": mask unexpectedly does not match", c.descr)
40 t.Errorf("RetCode: %064b", uint64(c.rc))
41 t.Errorf("Mask: %064b", c.mask)
42 t.Errorf("And: %064b", uint64(c.rc)&c.mask)
43 }
44 }
45 }
46
View as plain text