Skip to content

Commit ce0eb22

Browse files
committed
(MODULES-2391) SQLSERVER - Create Automated Tests For sqlserver_instance 2015-08-26
1 parent 0cefb67 commit ce0eb22

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
require 'spec_helper_acceptance'
2+
require 'securerandom'
3+
require 'erb'
4+
5+
host = find_only_one("sql_host")
6+
inst_name = "MSSQL" + SecureRandom.hex(4)
7+
inst_name = inst_name.upcase
8+
9+
describe "sqlserver_instance", :node => host do
10+
version = host['sql_version'].to_s
11+
12+
def ensure_sqlserver_instance(host, features, inst_name, ensure_val = 'present')
13+
manifest = <<-MANIFEST
14+
sqlserver_instance{'<%= inst_value %>':
15+
name => '<%= inst_value %>',
16+
ensure => <%= ensure_value %>,
17+
source => 'H:',
18+
features => [ <%= mssql_features %> ],
19+
sql_sysadmin_accounts => ['Administrator'],
20+
agt_svc_account => 'Administrator',
21+
agt_svc_password => 'Qu@lity!',
22+
}
23+
MANIFEST
24+
25+
inst_value = inst_name
26+
ensure_value = ensure_val
27+
mssql_features = features.map{ |x| "'#{x}'"}.join(', ')
28+
29+
pp = ERB.new(manifest).result(binding)
30+
31+
apply_manifest_on(host, pp) do |r|
32+
expect(r.stderr).not_to match(/Error/i)
33+
end
34+
end
35+
36+
context "can create sqlserver instance: #{inst_name}" do
37+
38+
features = ['SQL', 'SQLEngine', 'Replication', 'FullText', 'DQ']
39+
40+
before(:all) do
41+
ensure_sqlserver_instance(host, features, inst_name, 'absent')
42+
remove_sql_features(host, {:features => features, :version => version})
43+
end
44+
45+
after(:all) do
46+
ensure_sqlserver_instance(host, features, inst_name, 'absent')
47+
remove_sql_features(host, {:features => features, :version => version})
48+
end
49+
50+
it "create #{inst_name} instance" do
51+
ensure_sqlserver_instance(host, features, inst_name)
52+
53+
validate_sql_install(host, {:version => version}) do |r|
54+
expect(r.stdout).to match(/#{Regexp.new(inst_name)}/)
55+
end
56+
end
57+
58+
it "remove #{inst_name} instance" do
59+
remove_sql_features(host, {:features => features, :version => version})
60+
ensure_sqlserver_instance(host, features, inst_name, 'absent')
61+
62+
validate_sql_install(host, {:version => version}) do |r|
63+
expect(r.stdout).not_to match(/#{Regexp.new(inst_name)}/)
64+
end
65+
end
66+
end
67+
68+
context "can create instance with only SQL feature" do
69+
features = ['SQL']
70+
71+
before(:all) do
72+
ensure_sqlserver_instance(host, features, inst_name, 'absent')
73+
remove_sql_features(host, {:features => features, :version => version})
74+
end
75+
76+
after(:all) do
77+
ensure_sqlserver_instance(host, features, inst_name, 'absent')
78+
remove_sql_features(host, {:features => features, :version => version})
79+
end
80+
81+
it "create #{inst_name} instance" do
82+
ensure_sqlserver_instance(host, features, inst_name)
83+
84+
validate_sql_install(host, {:version => version}) do |r|
85+
expect(r.stdout).to match(/#{Regexp.new(inst_name)}/)
86+
end
87+
end
88+
end
89+
90+
context "can create instance with only RS feature" do
91+
features = ['RS']
92+
93+
before(:all) do
94+
ensure_sqlserver_instance(host, features, inst_name, 'absent')
95+
remove_sql_features(host, {:features => features, :version => version})
96+
end
97+
98+
after(:all) do
99+
ensure_sqlserver_instance(host, features, inst_name, 'absent')
100+
remove_sql_features(host, {:features => features, :version => version})
101+
end
102+
103+
it "create #{inst_name} instance" do
104+
ensure_sqlserver_instance(host, features, inst_name)
105+
106+
validate_sql_install(host, {:version => version}) do |r|
107+
expect(r.stdout).to match(/#{Regexp.new(inst_name)}/)
108+
end
109+
end
110+
end
111+
112+
context "can create instance with only AS feature" do
113+
features = ['AS']
114+
115+
before(:all) do
116+
ensure_sqlserver_instance(host, features, inst_name, 'absent')
117+
remove_sql_features(host, {:features => features, :version => version})
118+
end
119+
120+
after(:all) do
121+
ensure_sqlserver_instance(host, features, inst_name, 'absent')
122+
remove_sql_features(host, {:features => features, :version => version})
123+
end
124+
125+
it "create #{inst_name} instance" do
126+
ensure_sqlserver_instance(host, features, inst_name)
127+
128+
validate_sql_install(host, {:version => version}) do |r|
129+
expect(r.stdout).to match(/#{Regexp.new(inst_name)}/)
130+
end
131+
end
132+
end
133+
134+
end

0 commit comments

Comments
 (0)