Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions spec/acceptance/sqlserver_instance_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
require 'spec_helper_acceptance'
require 'securerandom'
require 'erb'

host = find_only_one("sql_host")
inst_name = "MSSQL" + SecureRandom.hex(4)
inst_name = inst_name.upcase

describe "sqlserver_instance", :node => host do
version = host['sql_version'].to_s

def ensure_sqlserver_instance(host, features, inst_name, ensure_val = 'present')
manifest = <<-MANIFEST
sqlserver_instance{'<%= inst_value %>':
name => '<%= inst_value %>',
ensure => <%= ensure_value %>,
source => 'H:',
features => [ <%= mssql_features %> ],
sql_sysadmin_accounts => ['Administrator'],
agt_svc_account => 'Administrator',
agt_svc_password => 'Qu@lity!',
}
MANIFEST

inst_value = inst_name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just use the same values, there isn't much reason to create additional resources for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I changed back and forth the way to get the instance name and forgot to clean it. Will change it to use the same value, run it again and update the PR

ensure_value = ensure_val
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still have this value assigned for no reason, just use ensure_val instead of creating another variable.

mssql_features = features.map{ |x| "'#{x}'"}.join(', ')

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

apply_manifest_on(host, pp) do |r|
expect(r.stderr).not_to match(/Error/i)
end
end

context "can create sqlserver instance: #{inst_name}" do

features = ['SQL', 'SQLEngine', 'Replication', 'FullText', 'DQ']

before(:all) do
ensure_sqlserver_instance(host, features, inst_name, 'absent')
remove_sql_features(host, {:features => features, :version => version})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method will always return true because :acceptable_exit_codes => [0, 1, 2]. That doesn't seem right, can you explain why this always returns true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I reused the method without catching it accepts exit code 1. I'll talk to Travis on this one when he's back.
I'll update the code and remove the use of it in this PR which only need to create and delete instances

end

after(:all) do
ensure_sqlserver_instance(host, features, inst_name, 'absent')
remove_sql_features(host, {:features => features, :version => version})
end

it "create #{inst_name} instance" do
ensure_sqlserver_instance(host, features, inst_name)

validate_sql_install(host, {:version => version}) do |r|
expect(r.stdout).to match(/#{Regexp.new(inst_name)}/)
end
end

it "remove #{inst_name} instance" do
remove_sql_features(host, {:features => features, :version => version})
ensure_sqlserver_instance(host, features, inst_name, 'absent')

validate_sql_install(host, {:version => version}) do |r|
expect(r.stdout).not_to match(/#{Regexp.new(inst_name)}/)
end
end
end

context "can create instance with only SQL feature" do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reword to "can create instance with only one SQL feature".

features = ['SQL']

before(:all) do
ensure_sqlserver_instance(host, features, inst_name, 'absent')
remove_sql_features(host, {:features => features, :version => version})
end

after(:all) do
ensure_sqlserver_instance(host, features, inst_name, 'absent')
remove_sql_features(host, {:features => features, :version => version})
end

it "create #{inst_name} instance" do
ensure_sqlserver_instance(host, features, inst_name)

validate_sql_install(host, {:version => version}) do |r|
expect(r.stdout).to match(/#{Regexp.new(inst_name)}/)
end
end
end

context "can create instance with only RS feature" do
features = ['RS']

before(:all) do
ensure_sqlserver_instance(host, features, inst_name, 'absent')
remove_sql_features(host, {:features => features, :version => version})
end

after(:all) do
ensure_sqlserver_instance(host, features, inst_name, 'absent')
remove_sql_features(host, {:features => features, :version => version})
end

it "create #{inst_name} instance" do
ensure_sqlserver_instance(host, features, inst_name)

validate_sql_install(host, {:version => version}) do |r|
expect(r.stdout).to match(/#{Regexp.new(inst_name)}/)
end
end
end

context "can create instance with only AS feature" do
features = ['AS']

before(:all) do
ensure_sqlserver_instance(host, features, inst_name, 'absent')
remove_sql_features(host, {:features => features, :version => version})
end

after(:all) do
ensure_sqlserver_instance(host, features, inst_name, 'absent')
remove_sql_features(host, {:features => features, :version => version})
end

it "create #{inst_name} instance" do
ensure_sqlserver_instance(host, features, inst_name)

validate_sql_install(host, {:version => version}) do |r|
expect(r.stdout).to match(/#{Regexp.new(inst_name)}/)
end
end
end

end