Skip to content

Commit 50797ad

Browse files
authored
acc: simple conditional error injection (#3437)
## Why To test deployment when some of the resources fail to deploy. Static Server block is not enough, since error is needed on some resources but not others. ## Tests New self test.
1 parent cf7e107 commit 50797ad

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Local = true
2+
Cloud = false
3+
4+
[EnvMatrix]
5+
DATABRICKS_CLI_DEPLOYMENT = ["terraform", "direct-exp"]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
>>> musterr [CLI] schemas create schema-INJECT_ERROR main
3+
Error: INJECTED
4+
5+
Exit code (musterr): 1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# If INJECT_ERROR is present anywhere in the request, test server will reply with 500 error
2+
trace musterr $CLI schemas create schema-INJECT_ERROR main

libs/testserver/server.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package testserver
22

33
import (
4+
"bytes"
45
"encoding/json"
56
"fmt"
67
"io"
@@ -261,8 +262,17 @@ func (s *Server) Handle(method, path string, handler HandlerFunc) {
261262
s.RequestCallback(&request)
262263
}
263264

264-
respAny := handler(request)
265-
resp := normalizeResponse(s.t, respAny)
265+
var resp EncodedResponse
266+
267+
if bytes.Contains(request.Body, []byte("INJECT_ERROR")) {
268+
resp = EncodedResponse{
269+
StatusCode: 500,
270+
Body: []byte("INJECTED"),
271+
}
272+
} else {
273+
respAny := handler(request)
274+
resp = normalizeResponse(s.t, respAny)
275+
}
266276

267277
for k, v := range resp.Headers {
268278
w.Header()[k] = v

0 commit comments

Comments
 (0)