@@ -29,6 +29,7 @@ type mockService struct {
29
29
wsCloseCode int
30
30
statusResponseCode int
31
31
imageResponseCode int
32
+ cancelResponseCode int
32
33
httpAddr string
33
34
}
34
35
@@ -39,12 +40,13 @@ func TestMain(m *testing.M) {
39
40
}
40
41
41
42
const (
42
- authToken = "auth_token"
43
- stdoutContents = "some_output"
44
- imageContents = "image_contents"
45
- buildPath = "/v1/build"
46
- wsPath = "/v1/build-ws/"
47
- imagePath = "/v1/image"
43
+ authToken = "auth_token"
44
+ stdoutContents = "some_output"
45
+ imageContents = "image_contents"
46
+ buildPath = "/v1/build"
47
+ wsPath = "/v1/build-ws/"
48
+ imagePath = "/v1/image"
49
+ buildCancelSuffix = "/_cancel"
48
50
)
49
51
50
52
func newResponse (m * mockService , id string , def []byte , libraryRef string ) client.BuildInfo {
@@ -110,6 +112,15 @@ func (m *mockService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
110
112
m .t .Fatal (err )
111
113
}
112
114
}
115
+ } else if r .Method == http .MethodPut && strings .HasSuffix (r .RequestURI , buildCancelSuffix ) {
116
+ // Mock build cancellation endpoint
117
+ if m .cancelResponseCode == http .StatusNoContent {
118
+ w .WriteHeader (http .StatusNoContent )
119
+ } else {
120
+ if err := jsonresp .WriteError (w , "" , m .cancelResponseCode ); err != nil {
121
+ m .t .Fatal (err )
122
+ }
123
+ }
113
124
} else {
114
125
w .WriteHeader (http .StatusNotFound )
115
126
}
0 commit comments