Debian Codegraph @

bigquery/v2/apiv2_smoketests/job_integration_test.go

raw symbols SCIP
1 // Copyright 2025 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
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 // Make some assertions if the job finished after the first poll.
51 // This _should_ be the case, but the contract doesn't allow us to
52 // assert that it must be the case.
53 if bv := queryResp.GetJobComplete(); bv != nil && bv.Value {
54 if jobRef := queryResp.GetJobReference(); jobRef != nil {
55 // We ended up with a job. Ensure there's a reason at least.
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 }