Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyas-goenka committed Feb 4, 2025
1 parent 064c56c commit edfc5de
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 13 deletions.
39 changes: 39 additions & 0 deletions acceptance/bundle/scripts/test.toml
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
LocalOnly = true # Deployment currently fails when run locally; once that is fixed, remove this setting

[[Server]]
Pattern = "GET /api/2.0/preview/scim/v2/Me"
Response.Body = '''
{
"id": "1000012345",
"userName": "[email protected]"
}
'''

[[Server]]
Pattern = "GET /api/2.0/workspace/get-status"
Response.Body = '''
{
"object_id": 1001,
"path": "",
"object_type": "DIRECTORY",
"resource_id": "1001"
}
'''

[[Server]]
Pattern = "POST /api/2.0/workspace/mkdirs"
Response.Body = '''
{
"error_code": "FORBIDDEN",
"message": "Some error message"
}
'''

[[Server]]
Pattern = "POST /api/2.0/workspace-files/import-file/"
Response.Body = '''
{
"error_code": "RESOURCE_DOES_NOT_EXIST",
"message": "Some error message"
}
'''
Response.StatusCode = 404
4 changes: 0 additions & 4 deletions acceptance/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,4 @@ func AddHandlers(server *testserver.Server) {
},
}, http.StatusOK
})

server.Handle("POST /api/2.0/workspace/mkdirs", func(r *http.Request) (any, int) {
return "{}", http.StatusOK
})
}
2 changes: 1 addition & 1 deletion acceptance/workspace/jobs/create/out.requests.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"method":"POST","path":"/api/2.1/jobs/update","body":{"job_id":0}}
{"method":"POST","path":"/api/2.1/jobs/create","body":{"name":"abc"}}
12 changes: 4 additions & 8 deletions acceptance/workspace/jobs/create/output.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@

>>> [CLI] jobs update --json {"name":"abc"}
Warning: unknown field: name
at
in (inline):1:3

Error: No stub found for pattern: POST /api/2.1/jobs/update

Exit code: 1
>>> [CLI] jobs create --json {"name":"abc"}
{
"job_id":1111
}
18 changes: 18 additions & 0 deletions libs/testserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@ func New(t testutil.TestingT) *Server {
s.Handle("/", func(r *http.Request) (any, int) {
pattern := r.Method + " " + r.URL.Path

t.Errorf(`
----------------------------------------
No stub found for pattern: %s
To stub a response for this request, you can add
the following to test.toml:
[[Server]]
Pattern = %q
Response.Body = '''
<response body here>
'''
Response.StatusCode = <response status-code here>
----------------------------------------
`, pattern, pattern)

return apierr.APIError{
Message: "No stub found for pattern: " + pattern,
}, http.StatusNotFound
Expand Down

0 comments on commit edfc5de

Please sign in to comment.