-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathmain_test.go
212 lines (197 loc) · 5.6 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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package main
import (
"encoding/json"
"fmt"
"os/exec"
"testing"
S "github.com/AssemblyAI/assemblyai-cli/schemas"
"github.com/AssemblyAI/assemblyai-cli/utils"
U "github.com/AssemblyAI/assemblyai-cli/utils"
)
func TestVersion(t *testing.T) {
out, err := exec.Command("go", "run", "main.go", "-v", "--test").Output()
if err != nil {
fmt.Println(err)
}
version := utils.GetEnvWithKey("VERSION")
if version == nil {
t.Error("VERSION not set")
}
if string(out) != "AssemblyAI CLI "+*version+"\n" {
t.Errorf("Expected AssemblyAI CLI v1.13, got %s.", string(out))
}
}
func TestValidate(t *testing.T) {
out, err := exec.Command("go", "run", "main.go", "validate", "--test").Output()
if err != nil {
fmt.Println(err)
}
if string(out) != "Please start by running \033[1m\033[34massemblyai config [token]\033[0m\n" {
t.Errorf("Expected Please start by running \033[1m\033[34massemblyai config [token]\033[0m, got %s.", string(out))
}
}
func TestAuthBad(t *testing.T) {
out, err := exec.Command("go", "run", "main.go", "config", "invalid", "--test").Output()
if err != nil {
fmt.Println(err)
}
if string(out) != U.INVALID_TOKEN+"\n" {
t.Errorf("Expected Something just went wrong. Please try again., got %s.", string(out))
}
}
func TestAuthCorrect(t *testing.T) {
token := utils.GetEnvWithKey("TOKEN")
out, err := exec.Command("go", "run", "main.go", "config", *token, "--test").Output()
if err != nil {
fmt.Println(err)
}
if string(out) != "You're now authenticated.\n" {
t.Errorf("Expected You're now authenticated., got %s.", string(out))
}
}
func TestTranscribeInvalidFlags(t *testing.T) {
out, err := exec.Command("go", "run", "main.go", "transcribe", "-i", "invalid", "-o", "invalid", "--test").Output()
if err != nil {
fmt.Println(err)
}
if string(out) != "\nrequires at least 1 arg(s), only received 0\n" {
t.Errorf("Expected requires at least 1 arg(s), only received 0, got %s.", string(out))
}
}
func TestTranscribeBadYoutube(t *testing.T) {
out, err := exec.Command("go", "run", "main.go", "transcribe", "https://www.youtube.com/watch?vs=m3cSH7jK3UU", "--test").Output()
if err != nil {
fmt.Println(err)
}
if string(out) != "\nCould not find YouTube ID in URL\n" {
t.Errorf("Expected Could not find YouTube ID in URL, got %s.", string(out))
}
}
func TestTranscribeBadFile(t *testing.T) {
out, err := exec.Command("go", "run", "main.go", "transcribe", "invalid", "--test").Output()
if err != nil {
fmt.Println(err)
}
if string(out) != "\nError opening file\n" {
t.Errorf("Expected Error opening file, got %s.", string(out))
}
}
func TestTranscribeWithFlags(t *testing.T) {
out, err := exec.Command(
"go",
"run",
"main.go",
"transcribe",
"https://storage.googleapis.com/aai-web-samples/2%20min.ogg",
"--auto_highlights",
"--content_moderation",
"--entity_detection",
"--format_text",
"--punctuate",
"--redact_pii",
"--sentiment_analysis",
"--speaker_labels",
"--summarization",
"--topic_detection",
"-p=false",
"-j",
"--test",
).Output()
if err != nil {
fmt.Println(err)
}
var result S.TranscriptResponse
json.Unmarshal(out, &result)
if *result.Status != "queued" {
t.Errorf("Expected queued, got %s.", *result.Status)
}
if *result.AutoHighlights != true {
t.Errorf("Expected Auto Highlights true, got false.")
}
if *result.ContentSafety != true {
t.Errorf("Expected Content Safety true, got false.")
}
if *result.EntityDetection != true {
t.Errorf("Expected Entity Detection true, got false.")
}
if *result.FormatText != true {
t.Errorf("Expected Format Text true, got false.")
}
if *result.Punctuate != true {
t.Errorf("Expected Punctuate true, got false.")
}
if *result.RedactPii != true {
t.Errorf("Expected RedactPII true, got false.")
}
if *result.SentimentAnalysis != true {
t.Errorf("Expected Sentiment Analysis true, got false.")
}
if result.SpeakerLabels != true {
t.Errorf("Expected Speaker Labels true, got false.")
}
if *result.Summarization != true {
t.Errorf("Expected Summarization true, got false.")
}
if *result.IabCategories != true {
t.Errorf("Expected IAB Categories(Topic detection) true, got false.")
}
}
func TestTranscribeRestrictions(t *testing.T) {
// Speaker Labels && Dual Channel
out, err := exec.Command(
"go",
"run",
"main.go",
"transcribe",
"https://storage.googleapis.com/aai-web-samples/2%20min.ogg",
"--speaker_labels",
"--dual_channel",
"-p=false",
"-j",
"--test",
).Output()
if err != nil {
fmt.Println(err)
}
if string(out) != "\nSpeaker labels are not supported for dual channel audio\n" {
t.Errorf("Expected Speaker labels are not supported for dual channel audio, got %s.", string(out))
}
// Auto Chapters && Summarization
out, err = exec.Command(
"go",
"run",
"main.go",
"transcribe",
"https://storage.googleapis.com/aai-web-samples/2%20min.ogg",
"--auto_chapters",
"--summarization",
"-p=false",
"-j",
"--test",
).Output()
if err != nil {
fmt.Println(err)
}
if string(out) != "\nAuto chapters are not supported for summarization\n" {
t.Errorf("Expected Auto chapters are not supported for summarization, got %s.", string(out))
}
// Language Detection && Language Code
out, err = exec.Command(
"go",
"run",
"main.go",
"transcribe",
"https://storage.googleapis.com/aai-web-samples/2%20min.ogg",
"--language_detection",
"--language_code=en-US",
"-p=false",
"-j",
"--test",
).Output()
if err != nil {
fmt.Println(err)
}
if string(out) != "\nPlease provide either language detection or language code, not both.\n" {
t.Errorf("Expected Please provide either language detection or language code, not both., got %s.", string(out))
}
}