googleapis / googleapis/google-cloud-go
httpreplay: bigquery response mismatch
- Dominant language
- Go
- Stars
- 4.5k
- Forks
- 1.6k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 109
Description
**Client**
bigquery
**Environment**
golang:1.19.7-alpine3.16
**Go Environment**
go version 1.19 linux/amd64
**Code**
```go
// Implementation
type BQClientT struct {
*bigquery.Client
}
func (c BQClientT) Read(ctx context.Context, q string, params []bigquery.QueryParameter) error {
query := c.Query(q)
query.Parameters = params
_, err := query.Run(ctx)
if err != nil {
return err
}
return nil
}
```
```go
// Unit test
func TestBQClientReadRecord(t *testing.T) {
ctx := context.Background()
file, err := os.Create("./recording")
if err != nil {
t.Fatal(err)
}
recorder, err := httpreplay.NewRecorder(file.Name(), nil)
if err != nil {
t.Fatalf("failed to create recorder: %v", err)
}
defer recorder.Close()
decodedKey, err := base64.StdEncoding.DecodeString(`my key`)
if err != nil {
t.Fatal(err)
}
creds, err := google.CredentialsFromJSON(ctx, decodedKey, bigquery.Scope)
if err != nil {
t.Fatal(err)
}
hc, err := recorder.Client(ctx, option.WithScopes(bigquery.Scope), option.WithCredentials(creds))
if err != nil {
t.Fatal(err)
}
client, err := bigquery.NewClient(ctx, creds.ProjectID, option.WithScopes(bigquery.Scope), option.WithHTTPClient(hc))
if err != nil {
t.Fatalf("failed to create bigquery client: %v", err)
}
bqClient := BQClient{Client: client}
query := "my query"
params := []bigquery.QueryParameter{
{
Name: "num",
Value: 1,
},
}
err = bqClient.Read(ctx, query, params)
if err != nil {
t.Fatalf("failed to read: %v", err)
}
}
func TestBQClientRead(t *testing.T) {
ctx := context.Background()
replayer, err := httpreplay.NewReplayer("../testdata/recording/.partitions")
if err != nil {
t.Fatalf("failed to load recorded data: %v", err)
}
defer replayer.Close()
hc, err := replayer.Client(ctx)
if err != nil {
t.Fatal(err)
}
client, err := bigquery.NewClient(ctx, "project-id", option.WithScopes(bigquery.Scope), option.WithHTTPClient(hc))
if err != nil {
t.Fatalf("failed to create bigquery client: %v", err)
}
bqClient := BQClient{Client: client}
query := "my query"
params := []bigquery.QueryParameter{
{
Name: "num",
Value: 1,
},
}
err = bqClient.Read(ctx, query, params)
if err != nil {
t.Fatalf("failed to read: %v", err)
}
}
```
**Expected behavior**
Test cases should execute without error
**Actual behavior**
"martian: failed to round trip: no matching request for .."
**Additional context**
The test cases fail with the error message "martian: failed to round trip: no matching request for ..". I added a log statement in https://github.com/googleapis/google-cloud-go/blob/main/httpreplay/internal/proxy/replay.go#L173 to identify the issue.
got the following result with the log `statment fmt.Println(string(p1), string(cand.BodyParts[i]))`
```
{"configuration":{"query":{"query":"my query","queryParameters":[{"name":"num","parameterType":{"type":"INT64"},"parameterValue":{"value":"1"}}],"useLegacySql":false}},"jobReference":{"jobId":"WF0eL5........","projectId":"project-id"}}
{"configuration":{"query":{"query":"my query","queryParameters":[{"name":"num","parameterType":{"type":"INT64"},"parameterValue":{"value":"1"}}],"useLegacySql":false}},"jobReference":{"jobId":"xFdbB9U6P.......,"projectId":"project-id"}}
```
The jobReference id mismatch causes the error.
Contributor guide
Assessment
This issue has not been assessed yet.