| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
package smoketests |
| 16 |
|
| 17 |
import ( |
| 18 |
"context" |
| 19 |
"testing" |
| 20 |
|
| 21 |
"cloud.google.com/go/bigquery/v2/apiv2/bigquerypb" |
| 22 |
"google.golang.org/protobuf/types/known/wrapperspb" |
| 23 |
) |
| 24 |
|
| 25 |
func TestInitStatelessQuery(t *testing.T) { |
| 26 |
if len(testClients) == 0 { |
| 27 |
t.Skip("integration tests skipped") |
| 28 |
} |
| 29 |
for k, client := range testClients { |
| 30 |
t.Run(k, func(t *testing.T) { |
| 31 |
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 32 |
defer cancel() |
| 33 |
|
| 34 |
req := &bigquerypb.PostQueryRequest{ |
| 35 |
ProjectId: testProjectID, |
| 36 |
QueryRequest: &bigquerypb.QueryRequest{ |
| 37 |
Query: "SELECT CURRENT_TIMESTAMP() as foo, SESSION_USER() as bar", |
| 38 |
JobCreationMode: bigquerypb.QueryRequest_JOB_CREATION_OPTIONAL, |
| 39 |
UseLegacySql: &wrapperspb.BoolValue{Value: false}, |
| 40 |
FormatOptions: &bigquerypb.DataFormatOptions{ |
| 41 |
UseInt64Timestamp: true, |
| 42 |
}, |
| 43 |
}, |
| 44 |
} |
| 45 |
|
| 46 |
queryResp, err := client.Query(ctx, req) |
| 47 |
if err != nil { |
| 48 |
t.Fatalf("Query() error: %v", err) |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
if bv := queryResp.GetJobComplete(); bv != nil && bv.Value { |
| 54 |
if jobRef := queryResp.GetJobReference(); jobRef != nil { |
| 55 |
|
| 56 |
if queryResp.GetJobCreationReason() != nil { |
| 57 |
t.Error("there's a job reference in the response but no reason for it") |
| 58 |
} |
| 59 |
} else { |
| 60 |
if rowcount := len(queryResp.GetRows()); rowcount != 1 { |
| 61 |
t.Errorf("expected one row of data, got %d", rowcount) |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
}) |
| 66 |
} |
| 67 |
} |