forked from CyCoreSystems/ari-proxy
/
sound.go
88 lines (67 loc) · 2.17 KB
/
sound.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
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
package integration
import (
"errors"
"testing"
"github.com/CyCoreSystems/ari"
)
func TestSoundData(t *testing.T, s Server) {
key := ari.NewKey(ari.SoundKey, "s1")
runTest("ok", t, s, func(t *testing.T, m *mock, cl ari.Client) {
var sd ari.SoundData
sd.ID = "s1"
sd.Text = "text"
m.Sound.On("Data", key).Return(&sd, nil)
ret, err := cl.Sound().Data(key)
if err != nil {
t.Errorf("Unexpected error in Sound Data: %s", err)
}
if ret == nil {
t.Errorf("Expected data to be non-nil")
} else {
if ret.ID != sd.ID || ret.Text != sd.Text {
t.Errorf("Expected '%v', got '%v'", sd, ret)
}
}
m.Shutdown()
m.Sound.AssertCalled(t, "Data", key)
})
runTest("err", t, s, func(t *testing.T, m *mock, cl ari.Client) {
m.Sound.On("Data", key).Return(nil, errors.New("error"))
_, err := cl.Sound().Data(key)
if err == nil {
t.Errorf("Expected error in Sound Data: %s", err)
}
m.Shutdown()
m.Sound.AssertCalled(t, "Data", key)
})
}
func TestSoundList(t *testing.T, s Server) {
runTest("ok", t, s, func(t *testing.T, m *mock, cl ari.Client) {
sh1 := ari.NewKey(ari.SoundKey, "sh1")
sh2 := ari.NewKey(ari.SoundKey, "sh2")
var filter map[string]string
m.Sound.On("List", filter, &ari.Key{Kind: "", ID: "", Node: "", Dialog: "", App: ""}).Return([]*ari.Key{sh1, sh2}, nil)
ret, err := cl.Sound().List(nil, nil)
if err != nil {
t.Errorf("Unexpected error in Sound List: %s", err)
}
if len(ret) != 2 {
t.Errorf("Expected handle list length to be 2, got '%d'", len(ret))
}
m.Shutdown()
m.Sound.AssertCalled(t, "List", filter, &ari.Key{Kind: "", ID: "", Node: "", Dialog: "", App: ""})
})
runTest("err", t, s, func(t *testing.T, m *mock, cl ari.Client) {
var filter map[string]string
m.Sound.On("List", filter, &ari.Key{Kind: "", ID: "", Node: "", Dialog: "", App: ""}).Return(nil, errors.New("error"))
ret, err := cl.Sound().List(nil, nil)
if err == nil {
t.Errorf("Expected error in Sound Data: %s", err)
}
if len(ret) != 0 {
t.Errorf("Expected handle list length to be 0, got '%d'", len(ret))
}
m.Shutdown()
m.Sound.AssertCalled(t, "List", filter, &ari.Key{Kind: "", ID: "", Node: "", Dialog: "", App: ""})
})
}