22//
33// Licensed under the Apache License, Version 2.0 (the "License");
44// you may not use this file except in compliance with the License.
5- // You may
6- // obtain a copy of the License at
5+ // You may obtain a copy of the License at
76//
87// https://www.apache.org/licenses/LICENSE-2.0
98//
@@ -25,30 +24,29 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
2524namespace {
2625using ::google::bigtable::v2::PrepareQueryResponse;
2726
28- class BasicInputs {
29- public:
27+ TEST (PreparedQuery, DefaultConstructor) {
3028 CompletionQueue cq;
31- Project p = Project (" dummy-project" );
32- InstanceResource instance = InstanceResource (p, " dummy-instance" );
33- std::string statement_contents =
34- " SELECT * FROM my_table WHERE col1 = @val1 and col2 = @val2;" ;
35- SqlStatement sql_statement = SqlStatement (statement_contents);
29+ Project p (" dummy-project" );
30+ InstanceResource instance (p, " dummy-instance" );
31+ std::string statement_contents (
32+ " SELECT * FROM my_table WHERE col1 = @val1 and col2 = @val2;" ) ;
33+ SqlStatement sql_statement (statement_contents);
3634 PrepareQueryResponse response;
37- std::unordered_map<std::string, Value> parameters = {{" val1" , Value (true )},
38- {" val2" , Value (2.0 )}};
39- };
40-
41- TEST (PreparedQuery, DefaultConstructor) {
42- auto inputs = BasicInputs ();
43- PreparedQuery q (inputs.cq , inputs.instance , inputs.sql_statement ,
44- inputs.response );
45- EXPECT_EQ (inputs.instance .FullName (), q.instance ().FullName ());
46- EXPECT_EQ (inputs.statement_contents , q.sql_statement ().sql ());
35+ PreparedQuery q (cq, instance, sql_statement, response);
36+ EXPECT_EQ (instance.FullName (), q.instance ().FullName ());
37+ EXPECT_EQ (statement_contents, q.sql_statement ().sql ());
4738}
4839
4940TEST (BoundQuery, FromPreparedQuery) {
50- auto inputs = BasicInputs ();
51- auto response = PrepareQueryResponse ();
41+ CompletionQueue cq;
42+ Project p (" dummy-project" );
43+ InstanceResource instance (p, " dummy-instance" );
44+ std::string statement_contents (
45+ " SELECT * FROM my_table WHERE col1 = @val1 and col2 = @val2;" );
46+ SqlStatement sql_statement (statement_contents);
47+ PrepareQueryResponse response;
48+ std::unordered_map<std::string, Value> parameters = {{" val1" , Value (true )},
49+ {" val2" , Value (2.0 )}};
5250
5351 // The following variables are only meant to confirm the metadata is correctly
5452 // passed down to the BoundQuery.
@@ -60,27 +58,35 @@ TEST(BoundQuery, FromPreparedQuery) {
6058 metadata->set_allocated_proto_schema (schema.release ());
6159 response.set_allocated_metadata (metadata.release ());
6260
63- PreparedQuery pq (inputs. cq , inputs. instance , inputs. sql_statement , response);
64- auto bq = pq.BindParameters (inputs. parameters );
65- EXPECT_EQ (inputs. instance .FullName (), bq.instance ().FullName ());
66- EXPECT_EQ (inputs. statement_contents , bq.prepared_query ());
67- EXPECT_EQ (inputs. parameters , bq.parameters ());
61+ PreparedQuery pq (cq, instance, sql_statement, response);
62+ auto bq = pq.BindParameters (parameters);
63+ EXPECT_EQ (instance.FullName (), bq.instance ().FullName ());
64+ EXPECT_EQ (statement_contents, bq.prepared_query ());
65+ EXPECT_EQ (parameters, bq.parameters ());
6866 EXPECT_TRUE (bq.metadata ().has_proto_schema ());
6967 EXPECT_EQ (1 , bq.metadata ().proto_schema ().columns_size ());
7068 EXPECT_EQ (" col1" , bq.metadata ().proto_schema ().columns ()[0 ].name ());
7169}
7270
7371TEST (BoundQuery, ToRequestProto) {
74- auto inputs = BasicInputs ();
75- PreparedQuery pq (inputs.cq , inputs.instance , inputs.sql_statement ,
76- inputs.response );
77- auto bq = pq.BindParameters (inputs.parameters );
72+ CompletionQueue cq;
73+ Project p (" dummy-project" );
74+ InstanceResource instance (p, " dummy-instance" );
75+ std::string statement_contents (
76+ " SELECT * FROM my_table WHERE col1 = @val1 and col2 = @val2;" );
77+ SqlStatement sql_statement (statement_contents);
78+ PrepareQueryResponse response;
79+ std::unordered_map<std::string, Value> parameters = {{" val1" , Value (true )},
80+ {" val2" , Value (2.0 )}};
81+
82+ PreparedQuery pq (cq, instance, sql_statement, response);
83+ auto bq = pq.BindParameters (parameters);
7884 google::bigtable::v2::ExecuteQueryRequest proto = bq.ToRequestProto ();
79- EXPECT_EQ (inputs. instance .FullName (), proto.instance_name ());
80- EXPECT_EQ (inputs. statement_contents , proto.prepared_query ());
85+ EXPECT_EQ (instance.FullName (), proto.instance_name ());
86+ EXPECT_EQ (statement_contents, proto.prepared_query ());
8187
8288 // Test param contents.
83- EXPECT_EQ (inputs. parameters .size (), proto.mutable_params ()->size ());
89+ EXPECT_EQ (parameters.size (), proto.mutable_params ()->size ());
8490
8591 // The first parameter is a boolean.
8692 EXPECT_TRUE (proto.params ().contains (" val1" ));
0 commit comments