|
| 1 | +# Copyright 2026 Google, Inc |
| 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 | +# http://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 | +require_relative "../spanner_isolation_level" |
| 16 | +require "rspec" |
| 17 | +require "google/cloud/spanner" |
| 18 | + |
| 19 | +describe "Spanner Isolation Level Options" do |
| 20 | + it "runs isolation level snippet successfully" do |
| 21 | + if ENV["GOOGLE_CLOUD_SPANNER_TEST_INSTANCE"].nil? || ENV["GOOGLE_CLOUD_SPANNER_PROJECT"].nil? |
| 22 | + skip "GOOGLE_CLOUD_SPANNER_TEST_INSTANCE and/or GOOGLE_CLOUD_SPANNER_PROJECT not defined" |
| 23 | + end |
| 24 | + |
| 25 | + @project_id = ENV["GOOGLE_CLOUD_SPANNER_PROJECT"] |
| 26 | + @instance_id = ENV["GOOGLE_CLOUD_SPANNER_TEST_INSTANCE"] |
| 27 | + @seed = SecureRandom.hex 8 |
| 28 | + @database_id = "test_db_#{@seed}" |
| 29 | + @spanner = Google::Cloud::Spanner.new project: @project_id |
| 30 | + @instance = @spanner.instance @instance_id |
| 31 | + |
| 32 | + unless @instance.database @database_id |
| 33 | + real_stdout = $stdout |
| 34 | + $stdout = StringIO.new |
| 35 | + create_database project_id: @project_id, |
| 36 | + instance_id: @instance_id, |
| 37 | + database_id: @database_id |
| 38 | + $stdout = real_stdout |
| 39 | + end |
| 40 | + |
| 41 | + client = @spanner.client @instance_id, @database_id |
| 42 | + client.insert "Singers", [{ SingerId: 1, FirstName: "Test" }] |
| 43 | + client.insert "Albums", [{ SingerId: 1, AlbumId: 1, AlbumTitle: "Old Title" }] |
| 44 | + |
| 45 | + expect { |
| 46 | + spanner_isolation_level project_id: @project_id, instance_id: @instance_id, database_id: @database_id |
| 47 | + }.to output(/AlbumTitle: Old Title\n1 records updated./).to_stdout |
| 48 | + |
| 49 | + @instance.database(@database_id).drop |
| 50 | + end |
| 51 | +end |
0 commit comments