@@ -17,6 +17,7 @@ package cmd
17
17
18
18
import (
19
19
"bytes"
20
+ "context"
20
21
_ "embed"
21
22
"errors"
22
23
"fmt"
@@ -27,6 +28,7 @@ import (
27
28
"path/filepath"
28
29
"strings"
29
30
"testing"
31
+ "time"
30
32
31
33
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
32
34
"github.com/h2non/gock"
@@ -214,7 +216,7 @@ func TestFrontEndHandlerWithLocation(t *testing.T) {
214
216
215
217
func TestProxy (t * testing.T ) {
216
218
t .Run ("normal" , func (t * testing.T ) {
217
- gock .Off ()
219
+ defer gock .Off ()
218
220
219
221
gock .New ("http://localhost:8080" ).Post ("/api/v1/echo" ).Reply (http .StatusOK )
220
222
gock .New ("http://localhost:9090" ).Post ("/api/v1/echo" ).Reply (http .StatusOK )
@@ -228,7 +230,7 @@ func TestProxy(t *testing.T) {
228
230
})
229
231
230
232
t .Run ("no proxy" , func (t * testing.T ) {
231
- gock .Off ()
233
+ defer gock .Off ()
232
234
233
235
gock .New ("http://localhost:8080" ).Post ("/api/v1/echo" ).Reply (http .StatusOK )
234
236
@@ -286,18 +288,55 @@ func TestStartPlugins(t *testing.T) {
286
288
err = os .WriteFile (filepath .Join (dir , "stores.yaml" ), []byte (sampleStores ), 0644 )
287
289
assert .NoError (t , err )
288
290
289
- rootCmd := & cobra.Command {
290
- Use : "atest" ,
291
- }
292
- rootCmd .SetOut (io .Discard )
293
- rootCmd .AddCommand (createServerCmd (
294
- fakeruntime.FakeExecer {ExpectOS : "linux" , ExpectLookPathError : errors .New ("not-found" )},
295
- server .NewFakeHTTPServer (),
296
- ))
297
-
298
- rootCmd .SetArgs ([]string {"server" , "--config-dir" , dir , "--dry-run" , "--port=0" , "--http-port=0" })
299
- err = rootCmd .Execute ()
300
- assert .NoError (t , err )
291
+ t .Run ("dry-run" , func (t * testing.T ) {
292
+ rootCmd := & cobra.Command {
293
+ Use : "atest" ,
294
+ }
295
+ rootCmd .SetOut (io .Discard )
296
+ rootCmd .AddCommand (createServerCmd (
297
+ fakeruntime.FakeExecer {ExpectOS : "linux" , ExpectLookPathError : errors .New ("not-found" )},
298
+ server .NewFakeHTTPServer (),
299
+ ))
300
+
301
+ rootCmd .SetArgs ([]string {"server" , "--config-dir" , dir , "--dry-run" , "--port=0" , "--http-port=0" })
302
+ err = rootCmd .Execute ()
303
+ assert .NoError (t , err )
304
+ })
305
+
306
+ t .Run ("normal" , func (t * testing.T ) {
307
+ httpServer := server .NewDefaultHTTPServer ()
308
+ rootCmd := & cobra.Command {
309
+ Use : "atest" ,
310
+ }
311
+ rootCmd .SetOut (io .Discard )
312
+ rootCmd .AddCommand (createServerCmd (
313
+ fakeruntime.FakeExecer {ExpectOS : "linux" , ExpectLookPathError : errors .New ("not-found" )},
314
+ httpServer ,
315
+ ))
316
+
317
+ rootCmd .SetArgs ([]string {"server" , "--config-dir" , dir , "--port=0" , "--http-port=0" })
318
+ go func () {
319
+ err = rootCmd .Execute ()
320
+ assert .NoError (t , err )
321
+ }()
322
+
323
+ for httpServer .GetPort () == "" {
324
+ time .Sleep (time .Second )
325
+ }
326
+
327
+ defer func () {
328
+ httpServer .Shutdown (context .Background ())
329
+ }()
330
+ resp , err := http .Post (fmt .Sprintf ("http://localhost:%s/server.Runner/GetSuites" , httpServer .GetPort ()), util .JSON , nil )
331
+ if assert .NoError (t , err ) {
332
+ assert .Equal (t , http .StatusOK , resp .StatusCode )
333
+ }
334
+
335
+ resp , err = http .Get (fmt .Sprintf ("http://localhost:%s/metrics" , httpServer .GetPort ()))
336
+ if assert .NoError (t , err ) {
337
+ assert .Equal (t , http .StatusOK , resp .StatusCode )
338
+ }
339
+ })
301
340
}
302
341
303
342
type fakeResponseWriter struct {
0 commit comments