Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialize recorded requests with indentation in acceptance tests #2329

Merged
merged 2 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,17 +314,15 @@ func runTest(t *testing.T, dir, coverDir string, repls testdiff.ReplacementsCont
// Write the requests made to the server to a output file if the test is
// configured to record requests.
if config.RecordRequests {
f, err := os.OpenFile(filepath.Join(tmpDir, "out.requests.txt"), os.O_CREATE|os.O_WRONLY, 0o644)
f, err := os.OpenFile(filepath.Join(tmpDir, "out.requests.json"), os.O_CREATE|os.O_WRONLY, 0o644)
require.NoError(t, err)

for _, req := range server.Requests {
reqJson, err := json.Marshal(req)
require.NoError(t, err)
reqJson, err := json.MarshalIndent(server.Requests, "", " ")
require.NoError(t, err)

reqJsonWithRepls := repls.Replace(string(reqJson))
_, err = f.WriteString(reqJsonWithRepls + "\n")
require.NoError(t, err)
}
reqJsonWithRepls := repls.Replace(string(reqJson))
_, err = f.WriteString(reqJsonWithRepls + "\n")
require.NoError(t, err)

err = f.Close()
require.NoError(t, err)
Expand Down
9 changes: 9 additions & 0 deletions acceptance/workspace/jobs/create-error/out.requests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
shreyas-goenka marked this conversation as resolved.
Show resolved Hide resolved
{
"method": "POST",
"path": "/api/2.1/jobs/create",
"body": {
"name": "abc"
}
}
]
1 change: 0 additions & 1 deletion acceptance/workspace/jobs/create-error/out.requests.txt

This file was deleted.

17 changes: 17 additions & 0 deletions acceptance/workspace/jobs/create/out.requests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
{
"headers": {
"Authorization": [
"Bearer [DATABRICKS_TOKEN]"
],
"User-Agent": [
"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/jobs_create cmd-exec-id/[UUID] auth/pat"
]
},
"method": "POST",
"path": "/api/2.1/jobs/create",
"body": {
"name": "abc"
}
}
]
1 change: 0 additions & 1 deletion acceptance/workspace/jobs/create/out.requests.txt

This file was deleted.