Skip to content

Commit 92cee16

Browse files
committed
Merge pull request #146 from cyberious/SpecTests
(MODULES-2498) Fix the check on removal
2 parents fbaabc1 + b30b878 commit 92cee16

File tree

2 files changed

+39
-42
lines changed

2 files changed

+39
-42
lines changed

spec/acceptance/sqlserver_instance_spec.rb

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
host = find_only_one("sql_host")
66

7+
def new_random_instance_name
8+
("MSSQL" + SecureRandom.hex(4)).upcase.to_s
9+
end
10+
711
describe "sqlserver_instance", :node => host do
812
version = host['sql_version'].to_s
913

10-
def new_random_instance_name
11-
return ("MSSQL" + SecureRandom.hex(4)).upcase.to_s
12-
end
1314

1415
def ensure_sqlserver_instance(host, features, inst_name, ensure_val = 'present')
1516
manifest = <<-MANIFEST
@@ -24,7 +25,7 @@ def ensure_sqlserver_instance(host, features, inst_name, ensure_val = 'present')
2425
}
2526
MANIFEST
2627

27-
mssql_features = features.map{ |x| "'#{x}'"}.join(', ')
28+
mssql_features = features.map { |x| "'#{x}'" }.join(', ')
2829

2930
pp = ERB.new(manifest).result(binding)
3031

@@ -34,87 +35,83 @@ def ensure_sqlserver_instance(host, features, inst_name, ensure_val = 'present')
3435
end
3536

3637
context "Create an instance", {:testrail => ['88978', '89028', '89031', '89043', '89061']} do
38+
inst_name = new_random_instance_name
39+
features = ['SQL', 'SQLEngine', 'Replication', 'FullText', 'DQ']
3740

38-
before(:all) do
39-
@inst_name = new_random_instance_name
40-
@features = ['SQL', 'SQLEngine', 'Replication', 'FullText', 'DQ']
41-
end
42-
43-
it "create #{@inst_name} instance" do
44-
ensure_sqlserver_instance(host, @features, @inst_name)
41+
it "create #{inst_name} instance" do
42+
ensure_sqlserver_instance(host, features, inst_name)
4543

4644
validate_sql_install(host, {:version => version}) do |r|
47-
expect(r.stdout).to match(/#{Regexp.new(@inst_name)}/)
45+
expect(r.stdout).to match(/#{Regexp.new(inst_name)}/)
4846
end
4947
end
5048

51-
it "remove #{@inst_name} instance" do
52-
ensure_sqlserver_instance(host, @features, @inst_name, 'absent')
49+
it "remove #{inst_name} instance" do
50+
ensure_sqlserver_instance(host, features, inst_name, 'absent')
5351

52+
# Ensure all features for this instance are removed and the defaults are left alone
5453
validate_sql_install(host, {:version => version}) do |r|
55-
expect(r.stdout).not_to match(/#{Regexp.new(@inst_name)}/)
54+
expect(r.stdout).to match(/MSSQLSERVER\s+Database Engine Services/)
55+
expect(r.stdout).to match(/MSSQLSERVER\s+SQL Server Replication/)
56+
expect(r.stdout).to match(/MSSQLSERVER\s+Data Quality Services/)
57+
expect(r.stdout).not_to match(/#{inst_name}\s+Database Engine Services/)
58+
expect(r.stdout).not_to match(/#{inst_name}\s+SQL Server Replication/)
59+
expect(r.stdout).not_to match(/#{inst_name}\s+Data Quality Services/)
5660
end
5761
end
5862
end
5963

6064
context "Feature has only one 'SQL'", {:testrail => ['89032']} do
61-
62-
before(:all) do
63-
@inst_name = new_random_instance_name
64-
@features = ['SQL']
65-
end
65+
inst_name = new_random_instance_name
66+
features = ['SQL']
6667

6768
after(:all) do
68-
ensure_sqlserver_instance(host, @features, @inst_name, 'absent')
69+
ensure_sqlserver_instance(host, features, inst_name, 'absent')
6970
end
7071

71-
it "create #{@inst_name} instance with only one SQL feature" do
72-
ensure_sqlserver_instance(host, @features, @inst_name)
72+
it "create #{inst_name} instance with only one SQL feature" do
73+
ensure_sqlserver_instance(host, features, inst_name)
7374

7475
validate_sql_install(host, {:version => version}) do |r|
75-
expect(r.stdout).to match(/#{Regexp.new(@inst_name)}/)
76+
expect(r.stdout).to match(/#{inst_name}\s+Database Engine Services/)
77+
expect(r.stdout).to match(/#{inst_name}\s+SQL Server Replication/)
78+
expect(r.stdout).to match(/#{inst_name}\s+Data Quality Services/)
7679
end
7780
end
7881
end
7982

8083
context "Feature has only one 'RS'", {:testrail => ['89034']} do
81-
82-
before(:all) do
83-
@inst_name = new_random_instance_name
84-
@features = ['RS']
85-
end
84+
inst_name = new_random_instance_name
85+
features = ['RS']
8686

8787
after(:all) do
88-
ensure_sqlserver_instance(host, @features, @inst_name, 'absent')
88+
ensure_sqlserver_instance(host, features, inst_name, 'absent')
8989
end
9090

91-
it "create #{@inst_name} instance with only one RS feature" do
92-
ensure_sqlserver_instance(host, @features, @inst_name)
91+
it "create #{inst_name} instance with only one RS feature" do
92+
ensure_sqlserver_instance(host, features, inst_name)
9393

9494
validate_sql_install(host, {:version => version}) do |r|
95-
expect(r.stdout).to match(/#{Regexp.new(@inst_name)}/)
95+
expect(r.stdout).to match(/#{inst_name}\s+Reporting Services/)
9696
end
9797
end
9898
end
9999

100100
context "Feature has only one 'AS'", {:testrail => ['89033']} do
101-
102-
before(:all) do
103-
@inst_name = new_random_instance_name
104-
@features = ['AS']
105-
end
101+
inst_name = new_random_instance_name
102+
features = ['AS']
106103

107104
after(:all) do
108-
ensure_sqlserver_instance(host, @features, @inst_name, 'absent')
105+
ensure_sqlserver_instance(host, features, inst_name, 'absent')
109106
end
110107

111108
#skip below test due to ticket MODULES-2379, when the ticket was resolved
112109
# will change xit to it
113-
xit "create #{@inst_name} instance with only one AS feature" do
114-
ensure_sqlserver_instance(host, @features, @inst_name)
110+
xit "create #{inst_name} instance with only one AS feature" do
111+
ensure_sqlserver_instance(host, features, inst_name)
115112

116113
validate_sql_install(host, {:version => version}) do |r|
117-
expect(r.stdout).to match(/#{Regexp.new(@inst_name)}/)
114+
expect(r.stdout).to match(/#{Regexp.new(inst_name)}/)
118115
end
119116
end
120117
end

0 commit comments

Comments
 (0)