Skip to content

Commit 9e729b2

Browse files
committed
add VCR-style HTTP recording/replay for integration tests
1 parent d7bd2fa commit 9e729b2

21 files changed

+5268
-6
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ go.work.sum
2323

2424
# env file
2525
.env
26+
27+
.idea
28+
*.iml

flowable/rest_utils.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
// rest_utils.go centralizes HTTP helpers, default headers, and auth settings used by the package.
1010

11-
// Package-level auth and header configuration
11+
// Package-level auth, header, and HTTP client configuration
1212
var (
1313
AuthUser = ""
1414
AuthPass = ""
@@ -17,8 +17,15 @@ var (
1717
"Accept": "application/json",
1818
"Content-Type": "application/json",
1919
}
20+
HTTPClient *http.Client = &http.Client{}
2021
)
2122

23+
// SetHTTPClient allows callers to override the HTTP client used for REST requests.
24+
// This is useful for injecting a VCR recorder transport for testing.
25+
func SetHTTPClient(c *http.Client) {
26+
HTTPClient = c
27+
}
28+
2229
// SetAuth allows callers to override the basic auth credentials used for REST requests.
2330
func SetAuth(user, pass string) {
2431
AuthUser = user
@@ -51,15 +58,14 @@ func prepareRequest(req *http.Request) {
5158

5259
// restGet performs a GET request to the provided full URL and returns status, body bytes, and error.
5360
func restGet(fullURL string) (status int, body []byte, err error) {
54-
client := &http.Client{}
5561
req, err := http.NewRequest("GET", fullURL, nil)
5662
if err != nil {
5763
return -1, nil, err
5864
}
5965

6066
prepareRequest(req)
6167

62-
resp, err := client.Do(req)
68+
resp, err := HTTPClient.Do(req)
6369
if err != nil {
6470
return -1, nil, err
6571
}
@@ -73,15 +79,14 @@ func restGet(fullURL string) (status int, body []byte, err error) {
7379

7480
// restPost performs a POST request to the provided full URL with the given JSON payload.
7581
func restPost(fullURL string, payload []byte) (status int, body []byte, err error) {
76-
client := &http.Client{}
7782
req, err := http.NewRequest("POST", fullURL, bytes.NewReader(payload))
7883
if err != nil {
7984
return -1, nil, err
8085
}
8186

8287
prepareRequest(req)
8388

84-
resp, err := client.Do(req)
89+
resp, err := HTTPClient.Do(req)
8590
if err != nil {
8691
return -1, nil, err
8792
}

go.mod

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
module github.com/flowable/flowable-external-client-golang
22

3-
go 1.23.4
3+
go 1.24
4+
5+
require gopkg.in/dnaeon/go-vcr.v4 v4.0.6
6+
7+
require go.yaml.in/yaml/v4 v4.0.0-rc.3 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
go.yaml.in/yaml/v4 v4.0.0-rc.3 h1:3h1fjsh1CTAPjW7q/EMe+C8shx5d8ctzZTrLcs/j8Go=
2+
go.yaml.in/yaml/v4 v4.0.0-rc.3/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
3+
gopkg.in/dnaeon/go-vcr.v4 v4.0.6 h1:PiJkrakkmzc5s7EfBnZOnyiLwi7o7A9fwPzN0X2uwe0=
4+
gopkg.in/dnaeon/go-vcr.v4 v4.0.6/go.mod h1:sbq5oMEcM4PXngbcNbHhzfCP9OdZodLhrbRYoyg09HY=

test/integration/cassettes/TestAcquireJobs.yaml

Lines changed: 286 additions & 0 deletions
Large diffs are not rendered by default.

test/integration/cassettes/TestBPMNErrorWithErrorCode1.yaml

Lines changed: 393 additions & 0 deletions
Large diffs are not rendered by default.

test/integration/cassettes/TestBPMNErrorWithErrorCode2.yaml

Lines changed: 393 additions & 0 deletions
Large diffs are not rendered by default.

test/integration/cassettes/TestBPMNErrorWithoutErrorCode.yaml

Lines changed: 393 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)