-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathclient_test.go
53 lines (45 loc) · 1.09 KB
/
client_test.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
package sc
import (
"os"
"path"
"testing"
"time"
)
// skipIfNoScsynth skips a test if scsynth is not running.
// A timeout of 2 seconds is used to attempt a connection to scsynth
// since when it is running it should be local on the same machine
// and we should be able to connect very quickly.
func skipIfNoScsynth(t *testing.T, client *Client) {
if _, err := client.Status(2 * time.Second); err != nil {
t.SkipNow()
}
}
// This test requires a SuperCollider server to be running.
//
// scsynth -u 57120
//
func TestClient(t *testing.T) {
client, err := NewClient("udp", "127.0.0.1:57200", "127.0.0.1:57120", 5*time.Second)
if err != nil {
t.Fatal(err)
}
// TODO: only skip if there is not a supercollider server running
skipIfNoScsynth(t, client)
defer func() {
_ = <-client.doneChan
_ = client.Close()
}() // Best effort.
// read a buffer
cwd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
audioFile := path.Join(cwd, "kalimba_mono.wav")
buf, err := client.ReadBuffer(audioFile, 0)
if err != nil {
t.Fatal(err)
}
if buf == nil {
t.Fatalf("got nil buffer")
}
}