-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(MODULES-2392) Automated Tests for sqlserver::config #140
Merged
zreichert
merged 3 commits into
puppetlabs:master
from
phongdly:MODULES-2392/Create_Automated_Test_sqlserver-config
Aug 26, 2015
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
require 'spec_helper_acceptance' | ||
require 'securerandom' | ||
require 'erb' | ||
|
||
host = find_only_one("sql_host") | ||
|
||
# Get instance name | ||
INST_NAME = ("MSSQL" + SecureRandom.hex(4)).upcase | ||
|
||
# Get database name | ||
DB_NAME = ("DB" + SecureRandom.hex(4)).upcase | ||
|
||
describe "sqlserver::config test", :node => host do | ||
version = host['sql_version'].to_s | ||
|
||
def ensure_sqlserver_instance(host, ensure_val = 'present') | ||
create_new_instance= <<-MANIFEST | ||
sqlserver_instance{'#{INST_NAME}': | ||
ensure => '#{ensure_val}', | ||
source => 'H:', | ||
features => [ 'SQL' ], | ||
sql_sysadmin_accounts => ['Administrator'], | ||
security_mode => 'SQL', | ||
sa_pwd => 'Pupp3t1@', | ||
} | ||
MANIFEST | ||
|
||
apply_manifest_on(host, create_new_instance) do |r| | ||
expect(r.stderr).not_to match(/Error/i) | ||
end | ||
end | ||
|
||
context "can create sqlserver::config" do | ||
|
||
before(:all) do | ||
# Create new instance | ||
ensure_sqlserver_instance(host) | ||
|
||
# get credentials for new config | ||
@admin_user = "admin" + SecureRandom.hex(2) | ||
@admin_pass = 'Pupp3t1@' | ||
|
||
# get database user | ||
@db_user = "dbuser" + SecureRandom.hex(2) | ||
end | ||
|
||
after(:all) do | ||
# remove the newly created instance | ||
ensure_sqlserver_instance(host, 'absent') | ||
end | ||
|
||
it "Create New Admin Login:" do | ||
create_new_login = <<-MANIFEST | ||
sqlserver::config{'#{INST_NAME}': | ||
instance_name => '#{INST_NAME}', | ||
admin_user => 'sa', | ||
admin_pass => 'Pupp3t1@', | ||
} | ||
sqlserver::login{'#{@admin_user}': | ||
instance => '#{INST_NAME}', | ||
login_type => 'SQL_LOGIN', | ||
login => '#{@admin_user}', | ||
password => '#{@admin_pass}', | ||
svrroles => {'sysadmin' => 1}, | ||
} | ||
MANIFEST | ||
apply_manifest_on(host, create_new_login) do |r| | ||
expect(r.stderr).not_to match(/Error/i) | ||
end | ||
end | ||
|
||
it "Validate New Config WITH using instance_name in sqlserver::config" do | ||
pp = <<-MANIFEST | ||
sqlserver::config{'#{INST_NAME}': | ||
admin_user => '#{@admin_user}', | ||
admin_pass => '#{@admin_pass}', | ||
instance_name => '#{INST_NAME}', | ||
} | ||
sqlserver::database{'#{DB_NAME}': | ||
instance => '#{INST_NAME}', | ||
} | ||
MANIFEST | ||
apply_manifest_on(host, pp) do |r| | ||
expect(r.stderr).not_to match(/Error/i) | ||
end | ||
end | ||
|
||
it "Validate new login and database actualy created" do | ||
hostname = host.hostname | ||
query = "USE #{DB_NAME};" | ||
|
||
output = run_sql_query(host, {:query => query, :server => hostname, :instance => INST_NAME, :sql_admin_user => @admin_user, :sql_admin_pass => @admin_pass}) | ||
expect(output).to match(/Changed database context to '#{Regexp.new(DB_NAME)}'/) | ||
end | ||
|
||
it "Validate New Config WITHOUT using instance_name in sqlserver::config" do | ||
pp = <<-MANIFEST | ||
sqlserver::config{'#{INST_NAME}': | ||
admin_user => '#{@admin_user}', | ||
admin_pass => '#{@admin_pass}', | ||
} | ||
sqlserver::database{'#{DB_NAME}': | ||
instance => '#{INST_NAME}', | ||
} | ||
MANIFEST | ||
apply_manifest_on(host, pp) do |r| | ||
expect(r.stderr).not_to match(/Error/i) | ||
end | ||
end | ||
|
||
it "Negative test: sqlserver::config without admin_user" do | ||
pp = <<-MANIFEST | ||
sqlserver::config{'#{INST_NAME}': | ||
admin_pass => '#{@admin_pass}', | ||
instance_name => '#{INST_NAME}', | ||
} | ||
sqlserver::database{'#{DB_NAME}': | ||
instance => '#{INST_NAME}', | ||
} | ||
MANIFEST | ||
apply_manifest_on(host, pp, {:acceptable_exit_codes => [0,1]}) do |r| | ||
expect(r.stderr).to match(/Error: Must pass admin_user to Sqlserver/) | ||
|
||
end | ||
end | ||
|
||
it "Negative test: sqlserver::config without admin_pass" do | ||
pp = <<-MANIFEST | ||
sqlserver::config{'#{INST_NAME}': | ||
admin_user => '#{@admin_user}', | ||
instance_name => '#{INST_NAME}', | ||
} | ||
sqlserver::database{'#{DB_NAME}': | ||
instance => '#{INST_NAME}', | ||
} | ||
MANIFEST | ||
apply_manifest_on(host, pp, {:acceptable_exit_codes => [0,1]}) do |r| | ||
expect(r.stderr).to match(/Error: Must pass admin_pass to Sqlserver/) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reasoning for having a Regexp within a Regexp?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regexp within Regex is the only way I know to get it work, if not declare like that, it won't pass the variable #{DB_NAME} into the expression