forked from CyCoreSystems/ari-proxy
/
liverecording.go
161 lines (135 loc) · 5.19 KB
/
liverecording.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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package integration
import (
"errors"
"testing"
"time"
"github.com/CyCoreSystems/ari"
)
func TestLiveRecordingData(t *testing.T, s Server) {
runTest("ok", t, s, func(t *testing.T, m *mock, cl ari.Client) {
expected := ari.LiveRecordingData{
Name: "n1",
Format: "format",
Cause: "c1",
Silence: ari.DurationSec(3 * time.Second),
State: "st1",
Talking: ari.DurationSec(3 * time.Second),
TargetURI: "uri1",
Duration: ari.DurationSec(6 * time.Second),
}
key := ari.NewKey(ari.LiveRecordingKey, "lr1")
m.LiveRecording.On("Data", key).Return(&expected, nil)
ret, err := cl.LiveRecording().Data(key)
if err != nil {
t.Errorf("Unexpected error in liverecording Data: %s", err)
}
if ret == nil {
t.Errorf("Expected live recording data to be non-nil")
} else {
failed := false
failed = failed || ret.Name != expected.Name
failed = failed || ret.Format != expected.Format
failed = failed || ret.Cause != expected.Cause
failed = failed || ret.Silence != expected.Silence
failed = failed || ret.State != expected.State
failed = failed || ret.Talking != expected.Talking
failed = failed || ret.TargetURI != expected.TargetURI
failed = failed || ret.Duration != expected.Duration
if failed {
t.Errorf("Expected '%v', got '%v'", expected, ret)
}
}
m.LiveRecording.AssertCalled(t, "Data", key)
})
runTest("err", t, s, func(t *testing.T, m *mock, cl ari.Client) {
key := ari.NewKey(ari.LiveRecordingKey, "lr1")
m.LiveRecording.On("Data", key).Return(nil, errors.New("err"))
ret, err := cl.LiveRecording().Data(key)
if err == nil {
t.Errorf("Expected error in liverecording Data")
}
if ret != nil {
t.Errorf("Expected live recording data to be nil")
}
m.LiveRecording.AssertCalled(t, "Data", key)
})
}
func testLiveRecordingCommand(t *testing.T, m *mock, name string, id *ari.Key, expected error, fn func(*ari.Key) error) {
m.LiveRecording.On(name, id).Return(expected)
err := fn(id)
failed := false
failed = failed || err == nil && expected != nil
failed = failed || err != nil && expected == nil
failed = failed || err != nil && expected != nil && err.Error() != expected.Error()
if failed {
t.Errorf("Expected live recording %s(%s) to return '%v', got '%v'",
name, id, expected, err,
)
}
m.LiveRecording.AssertCalled(t, name, id)
}
/*
func TestLiveRecordingDelete(t *testing.T, s Server) {
key := ari.NewKey(ari.LiveRecordingKey, "lr1")
runTest("ok", t, s, func(t *testing.T, m *mock, cl ari.Client) {
testLiveRecordingCommand(t, m, "Delete", key, nil, cl.LiveRecording().Delete)
})
runTest("err", t, s, func(t *testing.T, m *mock, cl ari.Client) {
testLiveRecordingCommand(t, m, "Delete", key, errors.New("err"), cl.LiveRecording().Delete)
})
}
*/
func TestLiveRecordingMute(t *testing.T, s Server) {
key := ari.NewKey(ari.LiveRecordingKey, "lr1")
runTest("ok", t, s, func(t *testing.T, m *mock, cl ari.Client) {
testLiveRecordingCommand(t, m, "Mute", key, nil, cl.LiveRecording().Mute)
})
runTest("err", t, s, func(t *testing.T, m *mock, cl ari.Client) {
testLiveRecordingCommand(t, m, "Mute", key, errors.New("err"), cl.LiveRecording().Mute)
})
}
func TestLiveRecordingPause(t *testing.T, s Server) {
key := ari.NewKey(ari.LiveRecordingKey, "lr1")
runTest("ok", t, s, func(t *testing.T, m *mock, cl ari.Client) {
testLiveRecordingCommand(t, m, "Pause", key, nil, cl.LiveRecording().Pause)
})
runTest("err", t, s, func(t *testing.T, m *mock, cl ari.Client) {
testLiveRecordingCommand(t, m, "Pause", key, errors.New("err"), cl.LiveRecording().Pause)
})
}
func TestLiveRecordingStop(t *testing.T, s Server) {
key := ari.NewKey(ari.LiveRecordingKey, "lr1")
runTest("ok", t, s, func(t *testing.T, m *mock, cl ari.Client) {
testLiveRecordingCommand(t, m, "Stop", key, nil, cl.LiveRecording().Stop)
})
runTest("err", t, s, func(t *testing.T, m *mock, cl ari.Client) {
testLiveRecordingCommand(t, m, "Stop", key, errors.New("err"), cl.LiveRecording().Stop)
})
}
func TestLiveRecordingUnmute(t *testing.T, s Server) {
key := ari.NewKey(ari.LiveRecordingKey, "lr1")
runTest("ok", t, s, func(t *testing.T, m *mock, cl ari.Client) {
testLiveRecordingCommand(t, m, "Unmute", key, nil, cl.LiveRecording().Unmute)
})
runTest("err", t, s, func(t *testing.T, m *mock, cl ari.Client) {
testLiveRecordingCommand(t, m, "Unmute", key, errors.New("err"), cl.LiveRecording().Unmute)
})
}
func TestLiveRecordingResume(t *testing.T, s Server) {
key := ari.NewKey(ari.LiveRecordingKey, "lr1")
runTest("ok", t, s, func(t *testing.T, m *mock, cl ari.Client) {
testLiveRecordingCommand(t, m, "Resume", key, nil, cl.LiveRecording().Resume)
})
runTest("err", t, s, func(t *testing.T, m *mock, cl ari.Client) {
testLiveRecordingCommand(t, m, "Resume", key, errors.New("err"), cl.LiveRecording().Resume)
})
}
func TestLiveRecordingScrap(t *testing.T, s Server) {
key := ari.NewKey(ari.LiveRecordingKey, "lr1")
runTest("ok", t, s, func(t *testing.T, m *mock, cl ari.Client) {
testLiveRecordingCommand(t, m, "Scrap", key, nil, cl.LiveRecording().Scrap)
})
runTest("err", t, s, func(t *testing.T, m *mock, cl ari.Client) {
testLiveRecordingCommand(t, m, "Scrap", key, errors.New("err"), cl.LiveRecording().Scrap)
})
}