File tree 2 files changed +17
-3
lines changed
2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package job
2
2
3
3
import (
4
4
"context"
5
+ "errors"
5
6
"fmt"
6
7
"net/http"
7
8
"net/http/httputil"
@@ -69,7 +70,10 @@ func (cu *CurlJob) Description() string {
69
70
func (cu * CurlJob ) DumpResponse (body bool ) ([]byte , error ) {
70
71
cu .Lock ()
71
72
defer cu .Unlock ()
72
- return httputil .DumpResponse (cu .response , body )
73
+ if cu .response != nil {
74
+ return httputil .DumpResponse (cu .response , body )
75
+ }
76
+ return nil , errors .New ("response is nil" )
73
77
}
74
78
75
79
// JobStatus returns the status of the CurlJob.
Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ func TestMultipleExecution(t *testing.T) {
68
68
69
69
// check very often that we've only run one job
70
70
ticker := time .NewTicker (2 * time .Millisecond )
71
+ loop:
71
72
for i := 0 ; i < 1000 ; i ++ {
72
73
select {
73
74
case <- ticker .C :
@@ -76,7 +77,7 @@ func TestMultipleExecution(t *testing.T) {
76
77
}
77
78
case <- ctx .Done ():
78
79
t .Error ("should not have reached timeout" )
79
- break
80
+ break loop
80
81
}
81
82
}
82
83
@@ -122,7 +123,16 @@ func TestCurlJob(t *testing.T) {
122
123
}
123
124
}
124
125
125
- func TestCurlJobDescription (t * testing.T ) {
126
+ func TestCurlJob_DumpResponse (t * testing.T ) {
127
+ request , err := http .NewRequest (http .MethodGet , worldtimeapiURL , nil )
128
+ assert .IsNil (t , err )
129
+ httpJob := job .NewCurlJob (request )
130
+ response , err := httpJob .DumpResponse (false )
131
+ assert .IsNil (t , response )
132
+ assert .ErrorContains (t , err , "response is nil" )
133
+ }
134
+
135
+ func TestCurlJob_Description (t * testing.T ) {
126
136
postRequest , err := http .NewRequest (
127
137
http .MethodPost ,
128
138
worldtimeapiURL ,
You can’t perform that action at this time.
0 commit comments