File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -6,11 +6,14 @@ import (
66 "fmt"
77 "io"
88 "io/fs"
9+ "net"
10+ "net/http"
911 "os"
1012 "path"
1113 "path/filepath"
1214 "runtime"
1315 "testing"
16+ "time"
1417
1518 "go.k6.io/k6/errext"
1619
@@ -113,6 +116,48 @@ func TestHandleSummaryResultError(t *testing.T) {
113116 assertEqual (t , "file summary 2" , files [filePath2 ])
114117}
115118
119+ func TestServeHTTP (t * testing.T ) {
120+ t .Parallel ()
121+ testCases := []struct {
122+ name string
123+ addressSet bool
124+ }{
125+ {
126+ name : "address set" ,
127+ addressSet : true ,
128+ },
129+ {
130+ name : "address not set" ,
131+ addressSet : false ,
132+ },
133+ }
134+
135+ for _ , tc := range testCases {
136+ t .Run (tc .name , func (t * testing.T ) {
137+ t .Parallel ()
138+ ts := tests .NewGlobalTestState (t )
139+ cmd := & cmdRun {
140+ gs : ts .GlobalState ,
141+ }
142+ if tc .addressSet {
143+ ts .ExpectedExitCode = int (exitcodes .CannotStartRESTAPI )
144+ }
145+
146+ lis , err := (& net.ListenConfig {}).Listen (t .Context (), "tcp" , ts .Flags .Address )
147+ require .NoError (t , err )
148+ t .Cleanup (func () {
149+ require .NoError (t , lis .Close ())
150+ })
151+
152+ srv := & http.Server {
153+ Addr : lis .Addr ().String (),
154+ ReadHeaderTimeout : time .Millisecond ,
155+ }
156+ cmd .serveHTTP (srv , tc .addressSet )
157+ })
158+ }
159+ }
160+
116161func TestRunScriptErrorsAndAbort (t * testing.T ) {
117162 t .Parallel ()
118163 testCases := []struct {
You can’t perform that action at this time.
0 commit comments