forked from revdotcom/revai-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
80 lines (62 loc) · 1.14 KB
/
main_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
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
package revai
import (
"context"
"fmt"
"os"
"testing"
"time"
)
const (
testFileName = "./testdata/testaudio.mp3"
)
var (
testClient *Client
testJob *Job
testVocab *CustomVocabulary
)
func TestMain(m *testing.M) {
setup()
os.Exit(m.Run())
}
func setup() {
testClient = NewClient(os.Getenv("REV_AI_API_KEY"))
testJob = makeTestJob()
testVocab = makeTestVocab()
fmt.Println("sleeping for 1 minute to allow file to be processed")
time.Sleep(1 * time.Minute)
}
func makeTestJob() *Job {
f := getTestFile()
params := &NewFileJobParams{
Media: f, // some io.Reader
Filename: f.Name(),
}
ctx := context.Background()
job, err := testClient.Job.SubmitFile(ctx, params)
if err != nil {
panic(err)
}
return job
}
func makeTestVocab() *CustomVocabulary {
params := &CreateCustomVocabularyParams{
CustomVocabularies: []Phrase{
{
Phrases: []string{"hello"},
},
},
}
ctx := context.Background()
vocab, err := testClient.CustomVocabulary.Create(ctx, params)
if err != nil {
panic(err)
}
return vocab
}
func getTestFile() *os.File {
f, err := os.Open(testFileName)
if err != nil {
panic(err)
}
return f
}