File: apicallerror_test.go

package info (click to toggle)
golang-github-linbit-golinstor 0.55.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 480 kB
  • sloc: makefile: 11
file content (45 lines) | stat: -rw-r--r-- 997 bytes parent folder | download
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
package client

import (
	"testing"

	linstor "github.com/LINBIT/golinstor"
)

func TestRcIs(t *testing.T) {
	cases := []struct {
		descr    string
		rc       int64
		mask     uint64
		expectIs bool
	}{{
		descr:    "exact match",
		rc:       -4611686018406153244,
		mask:     linstor.FailNotEnoughNodes,
		expectIs: true,
	}, {
		descr:    "wrong value",
		rc:       -4611686018406153244,
		mask:     linstor.FailInvldNodeName,
		expectIs: false,
	}}

	for _, c := range cases {
		r := ApiCallRc{RetCode: c.rc}

		is := r.Is(c.mask)

		if is && !c.expectIs {
			t.Errorf("Case \"%s\": mask unexpectedly matches", c.descr)
			t.Errorf("RetCode: %064b", uint64(c.rc))
			t.Errorf("Mask:    %064b", c.mask)
			t.Errorf("And:     %064b", uint64(c.rc)&c.mask)
		}
		if !is && c.expectIs {
			t.Errorf("Case \"%s\": mask unexpectedly does not match", c.descr)
			t.Errorf("RetCode: %064b", uint64(c.rc))
			t.Errorf("Mask:    %064b", c.mask)
			t.Errorf("And:     %064b", uint64(c.rc)&c.mask)
		}
	}
}