@@ -50,13 +50,13 @@ func TestAudio(t *testing.T) {
50
50
51
51
ctx := context .Background ()
52
52
53
- dir , cleanup := createTestDirectory (t )
53
+ dir , cleanup := test . CreateTestDirectory (t )
54
54
defer cleanup ()
55
55
56
56
for _ , tc := range testcases {
57
57
t .Run (tc .name , func (t * testing.T ) {
58
58
path := filepath .Join (dir , "fake.mp3" )
59
- createTestFile (t , path )
59
+ test . CreateTestFile (t , path )
60
60
61
61
req := AudioRequest {
62
62
FilePath : path ,
@@ -98,13 +98,13 @@ func TestAudioWithOptionalArgs(t *testing.T) {
98
98
99
99
ctx := context .Background ()
100
100
101
- dir , cleanup := createTestDirectory (t )
101
+ dir , cleanup := test . CreateTestDirectory (t )
102
102
defer cleanup ()
103
103
104
104
for _ , tc := range testcases {
105
105
t .Run (tc .name , func (t * testing.T ) {
106
106
path := filepath .Join (dir , "fake.mp3" )
107
- createTestFile (t , path )
107
+ test . CreateTestFile (t , path )
108
108
109
109
req := AudioRequest {
110
110
FilePath : path ,
@@ -119,27 +119,6 @@ func TestAudioWithOptionalArgs(t *testing.T) {
119
119
}
120
120
}
121
121
122
- // createTestFile creates a fake file with "hello" as the content.
123
- func createTestFile (t * testing.T , path string ) {
124
- file , err := os .Create (path )
125
- checks .NoError (t , err , "failed to create file" )
126
-
127
- if _ , err = file .WriteString ("hello" ); err != nil {
128
- t .Fatalf ("failed to write to file %v" , err )
129
- }
130
- file .Close ()
131
- }
132
-
133
- // createTestDirectory creates a temporary folder which will be deleted when cleanup is called.
134
- func createTestDirectory (t * testing.T ) (path string , cleanup func ()) {
135
- t .Helper ()
136
-
137
- path , err := os .MkdirTemp (os .TempDir (), "" )
138
- checks .NoError (t , err )
139
-
140
- return path , func () { os .RemoveAll (path ) }
141
- }
142
-
143
122
// handleAudioEndpoint Handles the completion endpoint by the test server.
144
123
func handleAudioEndpoint (w http.ResponseWriter , r * http.Request ) {
145
124
var err error
@@ -190,10 +169,10 @@ func handleAudioEndpoint(w http.ResponseWriter, r *http.Request) {
190
169
}
191
170
192
171
func TestAudioWithFailingFormBuilder (t * testing.T ) {
193
- dir , cleanup := createTestDirectory (t )
172
+ dir , cleanup := test . CreateTestDirectory (t )
194
173
defer cleanup ()
195
174
path := filepath .Join (dir , "fake.mp3" )
196
- createTestFile (t , path )
175
+ test . CreateTestFile (t , path )
197
176
198
177
req := AudioRequest {
199
178
FilePath : path ,
0 commit comments