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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
package client_test
import (
"testing"
"github.com/stretchr/testify/assert"
linstor "github.com/LINBIT/golinstor"
"github.com/LINBIT/golinstor/client"
)
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 := client.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)
}
}
}
func TestApiCallErrorIs(t *testing.T) {
var err error
// Random, observed error
err = client.ApiCallError{
{
RetCode: 4611686018481137428,
Message: "Tie breaker marked for deletion",
ObjRefs: map[string]string{
"RscDfn": "test1",
"Node": "n2.example.com",
},
},
{
RetCode: 53739522,
Message: "Node: n2.example.com, Resource: test1 preparing for deletion.",
Details: "Node: n2.example.com, Resource: test1 UUID is: 54cb972d-13b1-4894-aa34-65c87b53e3af",
ObjRefs: map[string]string{
"RscDfn": "test1",
"Node": "n2.example.com",
},
},
{
RetCode: -4611686018373647389,
Message: "No connection to satellite 'n2.example.com'",
ObjRefs: map[string]string{
"RscDfn": "test1",
"Node": "n2.example.com",
},
},
{
RetCode: 53739523,
Message: "(n3.example.com) Resource 'test1' [DRBD] adjusted.",
ObjRefs: map[string]string{
"RscDfn": "test1",
"Node": "n2.example.com",
},
},
{
RetCode: 53739523,
Message: "Preparing deletion of resource on 'n3.example.com'",
ObjRefs: map[string]string{
"RscDfn": "test1",
"Node": "n2.example.com",
},
},
{
RetCode: 53739523,
Message: "(n1.example.com) Resource 'test1' [DRBD] adjusted.",
ObjRefs: map[string]string{
"RscDfn": "test1",
"Node": "n2.example.com",
},
},
{
RetCode: 53739523,
Message: "Preparing deletion of resource on 'n1.example.com'",
ObjRefs: map[string]string{
"RscDfn": "test1",
"Node": "n2.example.com",
},
},
{
RetCode: -4611686018373647386,
Message: "Deletion of resource 'test1' on node 'n2.example.com' failed due to an unhandled exception of type DelayedApiRcException. Exceptions have been converted to responses",
Details: "Node: n2.example.com, Resource: test1",
ErrorReportIds: []string{
"68663093-00000-000003",
},
ObjRefs: map[string]string{
"RscDfn": "test1",
"Node": "n2.example.com",
},
},
}
assert.True(t, client.IsApiCallError(err, linstor.FailNotConnected))
assert.True(t, client.IsApiCallError(err, linstor.FailUnknownError))
assert.False(t, client.IsApiCallError(err, linstor.FailNotEnoughNodes))
assert.False(t, client.IsApiCallError(err, linstor.FailAccDeniedCommand))
}
|