MCPcopy Create free account
hub / github.com/CyCoreSystems/ari-proxy / TestMailboxList

Function TestMailboxList

internal/integration/mailbox.go:10–61  ·  view source on GitHub ↗
(t *testing.T, s Server)

Source from the content-addressed store, hash-verified

8)
9
10func TestMailboxList(t *testing.T, s Server) {
11 runTest("empty", t, s, func(t *testing.T, m *mock, cl ari.Client) {
12 m.Mailbox.On("List", (*ari.Key)(nil)).Return([]*ari.Key{}, nil)
13
14 ret, err := cl.Mailbox().List(nil)
15 if err != nil {
16 t.Errorf("Unexpected error in remote List call")
17 }
18 if len(ret) != 0 {
19 t.Errorf("Expected return length to be 0, got %d", len(ret))
20 }
21
22 m.Shutdown()
23
24 m.Mailbox.AssertCalled(t, "List", (*ari.Key)(nil))
25 })
26
27 runTest("nonEmpty", t, s, func(t *testing.T, m *mock, cl ari.Client) {
28 h1 := ari.NewKey(ari.MailboxKey, "h1")
29 h2 := ari.NewKey(ari.MailboxKey, "h2")
30
31 m.Mailbox.On("List", (*ari.Key)(nil)).Return([]*ari.Key{h1, h2}, nil)
32
33 ret, err := cl.Mailbox().List(nil)
34 if err != nil {
35 t.Errorf("Unexpected error in remote List call")
36 }
37 if len(ret) != 2 {
38 t.Errorf("Expected return length to be 2, got %d", len(ret))
39 }
40
41 m.Shutdown()
42
43 m.Mailbox.AssertCalled(t, "List", (*ari.Key)(nil))
44 })
45
46 runTest("error", t, s, func(t *testing.T, m *mock, cl ari.Client) {
47 m.Mailbox.On("List", (*ari.Key)(nil)).Return(nil, errors.New("unknown error"))
48
49 ret, err := cl.Mailbox().List(nil)
50 if err == nil {
51 t.Errorf("Expected error in remote List call")
52 }
53 if len(ret) != 0 {
54 t.Errorf("Expected return length to be 0, got %d", len(ret))
55 }
56
57 m.Shutdown()
58
59 m.Mailbox.AssertCalled(t, "List", (*ari.Key)(nil))
60 })
61}
62
63func testMailboxCommand(t *testing.T, m *mock, name string, id *ari.Key, expected error, fn func(*ari.Key) error) {
64 m.Mailbox.On(name, id).Return(expected)

Callers 2

TestMailboxListFunction · 0.92
TestMailboxListFunction · 0.92

Calls 4

runTestFunction · 0.85
MailboxMethod · 0.80
NewMethod · 0.80
ListMethod · 0.65

Tested by

no test coverage detected