|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
| 15 | +require 'json' |
| 16 | + |
15 | 17 | project_id = attribute('project_id') |
16 | 18 | basename = attribute('name') |
17 | 19 | authorized_network = attribute('authorized_network') |
| 20 | +region = "us-central1" |
| 21 | + |
| 22 | +activation_policy = "ALWAYS" |
| 23 | +availability_type = "REGIONAL" |
| 24 | +data_disk_size_gb = 10 |
| 25 | +data_disk_type = "PD_SSD" |
| 26 | +kind = "sql#settings" |
| 27 | +pricing_plan = "PER_USE" |
| 28 | +replication_type = "SYNCHRONOUS" |
| 29 | +storage_auto_resize = true |
| 30 | +storage_auto_resize_limit = 0 |
| 31 | +tier = "db-custom-2-13312" |
| 32 | + |
| 33 | +describe command("gcloud --project='#{project_id}' sql instances describe #{basename} --format=json") do |
| 34 | + its(:exit_status) { should eq 0 } |
| 35 | + its(:stderr) { should eq '' } |
| 36 | + |
| 37 | + let!(:data) do |
| 38 | + if subject.exit_status == 0 |
| 39 | + JSON.parse(subject.stdout) |
| 40 | + else |
| 41 | + {} |
| 42 | + end |
| 43 | + end |
| 44 | + |
| 45 | + describe "mssql_ha_database" do |
| 46 | + it "global settings are valid" do |
| 47 | + expect(data['settings']['activationPolicy']).to eq "#{activation_policy}" |
| 48 | + expect(data['settings']['availabilityType']).to eq "#{availability_type}" |
| 49 | + expect(data['settings']['dataDiskSizeGb']).to eq "#{data_disk_size_gb}" |
| 50 | + expect(data['settings']['dataDiskType']).to eq "#{data_disk_type}" |
| 51 | + expect(data['settings']['kind']).to eq "#{kind}" |
| 52 | + expect(data['settings']['pricingPlan']).to eq "#{pricing_plan}" |
| 53 | + expect(data['settings']['replicationType']).to eq "#{replication_type}" |
| 54 | + expect(data['settings']['storageAutoResize']).to eq storage_auto_resize |
| 55 | + expect(data['settings']['storageAutoResizeLimit']).to eq "#{storage_auto_resize_limit}" |
| 56 | + expect(data['settings']['tier']).to eq "#{tier}" |
| 57 | + end |
| 58 | + |
| 59 | + it "backend type is valid" do |
| 60 | + expect(data['backendType']).to eq 'SECOND_GEN' |
| 61 | + end |
| 62 | + |
| 63 | + it "database versions is valid" do |
| 64 | + expect(data['databaseVersion']).to eq 'SQLSERVER_2017_STANDARD' |
| 65 | + end |
| 66 | + |
| 67 | + it "state is valid" do |
| 68 | + expect(data['state']).to eq 'RUNNABLE' |
| 69 | + end |
18 | 70 |
|
19 | | -describe google_sql_database_instance(project: project_id, database: basename) do |
20 | | - let(:expected_settings) { |
21 | | - { |
22 | | - activation_policy: "ALWAYS", |
23 | | - availability_type: "REGIONAL", |
24 | | - data_disk_size_gb: 10, |
25 | | - data_disk_type: "PD_SSD", |
26 | | - kind: "sql#settings", |
27 | | - pricing_plan: "PER_USE", |
28 | | - replication_type: "SYNCHRONOUS", |
29 | | - storage_auto_resize: true, |
30 | | - storage_auto_resize_limit: 0, |
31 | | - tier: "db-custom-2-13312", |
32 | | - } |
33 | | - } |
34 | | - let(:settings) { subject.settings.item } |
35 | | - let(:backup_configuration) { settings[:backup_configuration] } |
36 | | - let(:ip_configuration) { settings[:ip_configuration] } |
37 | | - let(:location_preference) { settings[:location_preference] } |
38 | | - let(:maintenance_window) { settings[:maintenance_window] } |
39 | | - let(:user_labels) { settings[:user_labels] } |
40 | | - |
41 | | - its(:backend_type) { should eq 'SECOND_GEN' } |
42 | | - its(:database_version) { should eq 'SQLSERVER_2017_STANDARD' } |
43 | | - its(:state) { should eq 'RUNNABLE' } |
44 | | - its(:region) { should eq 'us-central1' } |
45 | | - its(:gce_zone) { should eq 'us-central1-a' } |
46 | | - |
47 | | - it { expect(settings).to include(expected_settings) } |
48 | | - it { expect(ip_configuration).to include(authorized_networks: [{kind: 'sql#aclEntry', name: "#{project_id}-cidr", value: authorized_network}], ipv4_enabled: true, require_ssl: true) } |
49 | | - it { expect(location_preference).to include(kind: "sql#locationPreference", zone: "us-central1-a") } |
50 | | - it { expect(maintenance_window).to include(kind: "sql#maintenanceWindow", day: 7, hour: 12, update_track: "stable") } |
51 | | - it { expect(user_labels).to include(foo: "bar") } |
| 71 | + it "region is valid" do |
| 72 | + expect(data['region']).to eq region |
| 73 | + end |
| 74 | + |
| 75 | + it "gce zone is valid" do |
| 76 | + expect(data['gceZone']).to eq "#{region}-a" |
| 77 | + end |
| 78 | + |
| 79 | + it "location preference is valid" do |
| 80 | + expect(data['settings']['locationPreference']).to include( |
| 81 | + "kind" => "sql#locationPreference", |
| 82 | + "zone" => "#{region}-a") |
| 83 | + end |
| 84 | + |
| 85 | + it "maintenance window is valid" do |
| 86 | + expect(data['settings']['maintenanceWindow']).to include( |
| 87 | + "kind" => "sql#maintenanceWindow", |
| 88 | + "day" => 7, |
| 89 | + "hour" => 12, |
| 90 | + "updateTrack" => "stable") |
| 91 | + end |
| 92 | + |
| 93 | + it "ip configuration and authorized networks are valid" do |
| 94 | + expect(data['settings']['ipConfiguration']).to include( |
| 95 | + ["authorizedNetworks"][0] => [{ |
| 96 | + "kind" => "sql#aclEntry", |
| 97 | + "name" => "#{project_id}-cidr", |
| 98 | + "value" => authorized_network |
| 99 | + }], |
| 100 | + "ipv4Enabled" => true, |
| 101 | + "requireSsl" => true, |
| 102 | + ) |
| 103 | + end |
| 104 | + |
| 105 | + it "user labels are set" do |
| 106 | + expect(data['settings']['userLabels']).to include( |
| 107 | + "foo" => "bar") |
| 108 | + end |
| 109 | + end |
52 | 110 | end |
53 | 111 |
|
54 | | -describe google_sql_users(project: project_id, database: basename).where(user_name: /\Atftest/) do |
55 | | - its(:count) { should be 3 } |
56 | | - it { should exist } |
| 112 | +describe command("gcloud --project='#{project_id}' sql users list --instance #{basename} --format=json") do |
| 113 | + its(:exit_status) { should eq 0 } |
| 114 | + its(:stderr) { should eq '' } |
| 115 | + |
| 116 | + let!(:data) do |
| 117 | + if subject.exit_status == 0 |
| 118 | + JSON.parse(subject.stdout) |
| 119 | + else |
| 120 | + {} |
| 121 | + end |
| 122 | + end |
| 123 | + |
| 124 | + describe "mssql_ha_database" do |
| 125 | + it "has 3 users" do |
| 126 | + expect(data.select {|k,v| k['name'].start_with?("tftest")}.size).to eq 3 |
| 127 | + end |
| 128 | + end |
57 | 129 | end |
0 commit comments