Skip to content

Commit bc9b28f

Browse files
committed
Add tests for resource downloading
1 parent 35e7b07 commit bc9b28f

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

voice/recording_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package voice
2+
3+
import (
4+
"io/ioutil"
5+
"net/http"
6+
"testing"
7+
)
8+
9+
func TestRecordingGetFile(t *testing.T) {
10+
fileContents := []byte("this is not really a WAV file")
11+
mbClient, stop := testClient(http.StatusOK, []byte(fileContents))
12+
defer stop()
13+
14+
rec := &Recording{
15+
ID: "1337",
16+
links: map[string]string{
17+
"file": "/yolo/swag.wav",
18+
},
19+
}
20+
r, err := rec.DownloadFile(mbClient)
21+
if err != nil {
22+
t.Fatal(err)
23+
}
24+
wav, err := ioutil.ReadAll(r)
25+
if err != nil {
26+
t.Fatal(err)
27+
}
28+
if string(wav) != string(fileContents) {
29+
t.Logf("exp: %q", string(fileContents))
30+
t.Logf("got: %q", string(wav))
31+
t.Fatalf("mismatched downloaded contents")
32+
}
33+
}

voice/transcription_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package voice
2+
3+
import (
4+
"net/http"
5+
"testing"
6+
)
7+
8+
func TestTranscriptionGetContents(t *testing.T) {
9+
text := "the quick brown fox jumps over the lazy dog"
10+
mbClient, stop := testClient(http.StatusOK, []byte(text))
11+
defer stop()
12+
13+
trans := &Transcription{
14+
ID: "1337",
15+
links: map[string]string{
16+
"file": "/yolo/swag.txt",
17+
},
18+
}
19+
contents, err := trans.Contents(mbClient)
20+
if err != nil {
21+
t.Fatal(err)
22+
}
23+
if contents != text {
24+
t.Logf("exp: %q", text)
25+
t.Logf("got: %q", contents)
26+
t.Fatalf("mismatched downloaded contents")
27+
}
28+
}

0 commit comments

Comments
 (0)