-
Notifications
You must be signed in to change notification settings - Fork 553
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
259 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
google-cloud-bigquery/test/google/cloud/bigquery/dataset/routine_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright 2020 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
require "helper" | ||
|
||
describe Google::Cloud::Bigquery::Dataset, :routine, :mock_bigquery do | ||
let(:dataset_hash) { random_dataset_hash } | ||
let(:dataset_gapi) { Google::Apis::BigqueryV2::Dataset.from_json dataset_hash.to_json } | ||
let(:dataset) { Google::Cloud::Bigquery::Dataset.from_gapi dataset_gapi, bigquery.service } | ||
focus | ||
it "finds a routine" do | ||
found_routine_id = "found_routine" | ||
|
||
mock = Minitest::Mock.new | ||
mock.expect :get_routine, random_routine_full_hash(dataset.dataset_id, found_routine_id).to_json, [project, dataset.dataset_id, found_routine_id, options: { skip_deserialization: true }] | ||
dataset.service.mocked_service = mock | ||
|
||
routine = dataset.routine found_routine_id | ||
|
||
mock.verify | ||
|
||
routine.must_be_kind_of Google::Cloud::Bigquery::Routine | ||
routine.routine_id.must_equal found_routine_id | ||
end | ||
end |
183 changes: 183 additions & 0 deletions
183
google-cloud-bigquery/test/google/cloud/bigquery/dataset/routines_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
# Copyright 2020 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
require "helper" | ||
|
||
describe Google::Cloud::Bigquery::Dataset, :models, :mock_bigquery do | ||
let(:dataset_hash) { random_dataset_hash } | ||
let(:dataset_gapi) { Google::Apis::BigqueryV2::Dataset.from_json dataset_hash.to_json } | ||
let(:dataset) { Google::Cloud::Bigquery::Dataset.from_gapi dataset_gapi, bigquery.service } | ||
|
||
it "lists models" do | ||
mock = Minitest::Mock.new | ||
mock.expect :list_models, list_models_gapi_json(dataset.dataset_id, 3), | ||
[project, dataset.dataset_id, max_results: nil, page_token: nil, options: { skip_deserialization: true }] | ||
dataset.service.mocked_service = mock | ||
|
||
models = dataset.models | ||
|
||
mock.verify | ||
|
||
models.size.must_equal 3 | ||
models.each { |ds| ds.must_be_kind_of Google::Cloud::Bigquery::Model } | ||
end | ||
|
||
it "lists models with max set" do | ||
mock = Minitest::Mock.new | ||
mock.expect :list_models, list_models_gapi_json(dataset.dataset_id, 3, "next_page_token"), | ||
[project, dataset.dataset_id, max_results: 3, page_token: nil, options: { skip_deserialization: true }] | ||
dataset.service.mocked_service = mock | ||
|
||
models = dataset.models max: 3 | ||
|
||
mock.verify | ||
|
||
models.count.must_equal 3 | ||
models.each { |ds| ds.must_be_kind_of Google::Cloud::Bigquery::Model } | ||
models.token.wont_be :nil? | ||
models.token.must_equal "next_page_token" | ||
end | ||
|
||
it "paginates models" do | ||
mock = Minitest::Mock.new | ||
mock.expect :list_models, list_models_gapi_json(dataset.dataset_id, 3, "next_page_token"), | ||
[project, dataset.dataset_id, max_results: nil, page_token: nil, options: { skip_deserialization: true }] | ||
mock.expect :list_models, list_models_gapi_json(dataset.dataset_id, 2, nil), | ||
[project, dataset.dataset_id, max_results: nil, page_token: "next_page_token", options: { skip_deserialization: true }] | ||
dataset.service.mocked_service = mock | ||
|
||
first_models = dataset.models | ||
second_models = dataset.models token: first_models.token | ||
|
||
mock.verify | ||
|
||
first_models.count.must_equal 3 | ||
first_models.each { |ds| ds.must_be_kind_of Google::Cloud::Bigquery::Model } | ||
first_models.token.wont_be :nil? | ||
first_models.token.must_equal "next_page_token" | ||
|
||
second_models.count.must_equal 2 | ||
second_models.each { |ds| ds.must_be_kind_of Google::Cloud::Bigquery::Model } | ||
second_models.token.must_be :nil? | ||
end | ||
|
||
it "paginates models with next? and next" do | ||
mock = Minitest::Mock.new | ||
mock.expect :list_models, list_models_gapi_json(dataset.dataset_id, 3, "next_page_token"), | ||
[project, dataset.dataset_id, max_results: nil, page_token: nil, options: { skip_deserialization: true }] | ||
mock.expect :list_models, list_models_gapi_json(dataset.dataset_id, 2, nil), | ||
[project, dataset.dataset_id, max_results: nil, page_token: "next_page_token", options: { skip_deserialization: true }] | ||
dataset.service.mocked_service = mock | ||
|
||
first_models = dataset.models | ||
second_models = first_models.next | ||
|
||
mock.verify | ||
|
||
first_models.count.must_equal 3 | ||
first_models.each { |ds| ds.must_be_kind_of Google::Cloud::Bigquery::Model } | ||
first_models.token.wont_be :nil? | ||
first_models.token.must_equal "next_page_token" | ||
|
||
second_models.count.must_equal 2 | ||
second_models.each { |ds| ds.must_be_kind_of Google::Cloud::Bigquery::Model } | ||
second_models.token.must_be :nil? | ||
end | ||
|
||
it "paginates models with next? and next and max" do | ||
mock = Minitest::Mock.new | ||
mock.expect :list_models, list_models_gapi_json(dataset.dataset_id, 3, "next_page_token"), | ||
[project, dataset.dataset_id, max_results: 3, page_token: nil, options: { skip_deserialization: true }] | ||
mock.expect :list_models, list_models_gapi_json(dataset.dataset_id, 2, nil), | ||
[project, dataset.dataset_id, max_results: 3, page_token: "next_page_token", options: { skip_deserialization: true }] | ||
dataset.service.mocked_service = mock | ||
|
||
first_models = dataset.models max: 3 | ||
second_models = first_models.next | ||
|
||
mock.verify | ||
|
||
first_models.count.must_equal 3 | ||
first_models.each { |ds| ds.must_be_kind_of Google::Cloud::Bigquery::Model } | ||
first_models.next?.must_equal true | ||
|
||
second_models.count.must_equal 2 | ||
second_models.each { |ds| ds.must_be_kind_of Google::Cloud::Bigquery::Model } | ||
second_models.next?.must_equal false | ||
end | ||
|
||
it "paginates models with all" do | ||
mock = Minitest::Mock.new | ||
mock.expect :list_models, list_models_gapi_json(dataset.dataset_id, 3, "next_page_token"), | ||
[project, dataset.dataset_id, max_results: nil, page_token: nil, options: { skip_deserialization: true }] | ||
mock.expect :list_models, list_models_gapi_json(dataset.dataset_id, 2, nil), | ||
[project, dataset.dataset_id, max_results: nil, page_token: "next_page_token", options: { skip_deserialization: true }] | ||
dataset.service.mocked_service = mock | ||
|
||
models = dataset.models.all.to_a | ||
|
||
mock.verify | ||
|
||
models.count.must_equal 5 | ||
models.each { |ds| ds.must_be_kind_of Google::Cloud::Bigquery::Model } | ||
end | ||
|
||
it "paginates models with all and max" do | ||
mock = Minitest::Mock.new | ||
mock.expect :list_models, list_models_gapi_json(dataset.dataset_id, 3, "next_page_token"), | ||
[project, dataset.dataset_id, max_results: 3, page_token: nil, options: { skip_deserialization: true }] | ||
mock.expect :list_models, list_models_gapi_json(dataset.dataset_id, 2, nil), | ||
[project, dataset.dataset_id, max_results: 3, page_token: "next_page_token", options: { skip_deserialization: true }] | ||
dataset.service.mocked_service = mock | ||
|
||
models = dataset.models(max: 3).all.to_a | ||
|
||
mock.verify | ||
|
||
models.count.must_equal 5 | ||
models.each { |ds| ds.must_be_kind_of Google::Cloud::Bigquery::Model } | ||
end | ||
|
||
it "iterates models with all using Enumerator" do | ||
mock = Minitest::Mock.new | ||
mock.expect :list_models, list_models_gapi_json(dataset.dataset_id, 3, "next_page_token"), | ||
[project, dataset.dataset_id, max_results: nil, page_token: nil, options: { skip_deserialization: true }] | ||
mock.expect :list_models, list_models_gapi_json(dataset.dataset_id, 3, "second_page_token"), | ||
[project, dataset.dataset_id, max_results: nil, page_token: "next_page_token", options: { skip_deserialization: true }] | ||
dataset.service.mocked_service = mock | ||
|
||
models = dataset.models.all.take(5) | ||
|
||
mock.verify | ||
|
||
models.count.must_equal 5 | ||
models.each { |ds| ds.must_be_kind_of Google::Cloud::Bigquery::Model } | ||
end | ||
|
||
it "iterates models with all with request_limit set" do | ||
mock = Minitest::Mock.new | ||
mock.expect :list_models, list_models_gapi_json(dataset.dataset_id, 3, "next_page_token"), | ||
[project, dataset.dataset_id, max_results: nil, page_token: nil, options: { skip_deserialization: true }] | ||
mock.expect :list_models, list_models_gapi_json(dataset.dataset_id, 3, "second_page_token"), | ||
[project, dataset.dataset_id, max_results: nil, page_token: "next_page_token", options: { skip_deserialization: true }] | ||
dataset.service.mocked_service = mock | ||
|
||
models = dataset.models.all(request_limit: 1).to_a | ||
|
||
mock.verify | ||
|
||
models.count.must_equal 6 | ||
models.each { |ds| ds.must_be_kind_of Google::Cloud::Bigquery::Model } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters