-
Notifications
You must be signed in to change notification settings - Fork 21
(MODULES-2453) Create Automated Tests for sqlserver_tsql #141
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ def ensure_sqlserver_instance(host, ensure_val = 'present') | |
end | ||
end | ||
|
||
context "can create sqlserver::config" do | ||
context "server_url =>", {:testrail => ['89070', '89071', '89072', '89073']} do | ||
|
||
before(:all) do | ||
# Create new instance | ||
|
@@ -87,10 +87,10 @@ def ensure_sqlserver_instance(host, ensure_val = 'present') | |
|
||
it "Validate new login and database actualy created" do | ||
hostname = host.hostname | ||
query = "USE #{DB_NAME};" | ||
query = "USE #{DB_NAME}; SELECT * from master..sysdatabases WHERE name = '#{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)}'/) | ||
run_sql_query(host, {:query => query, :server => hostname, :instance => INST_NAME, \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think the '' character is necessary here. Ruby ignores whitespace. I would recommend this. run_sql_query_opts = {
:query => "USE #{DB_NAME}; SELECT * from master..sysdatabases WHERE name = '#{DB_NAME}'",
:sql_admin_user => @admin_user,
:sql_admin_pass => @admin_pass,
:expected_row_count => 1,
}
run_sql_query(host, run_sql_query_opts) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @zreichert , it looks much cleaner with your recommendation. Modified and pushed |
||
:sql_admin_user => @admin_user, :sql_admin_pass => @admin_pass, :expected_row_count => 1}) | ||
end | ||
|
||
it "Validate New Config WITHOUT using instance_name in sqlserver::config" do | ||
|
@@ -120,7 +120,6 @@ def ensure_sqlserver_instance(host, ensure_val = 'present') | |
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 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
require 'spec_helper_acceptance' | ||
require 'securerandom' | ||
require 'erb' | ||
|
||
host = find_only_one("sql_host") | ||
|
||
# database name | ||
DB_NAME = ("DB" + SecureRandom.hex(4)).upcase | ||
|
||
#database user: | ||
DB_LOGIN_USER = "loginuser" + SecureRandom.hex(2) | ||
|
||
describe "sqlserver_tsql test", :node => host do | ||
|
||
def ensure_sqlserver_database(host, ensure_val = 'present') | ||
pp = <<-MANIFEST | ||
sqlserver::config{'MSSQLSERVER': | ||
admin_user => 'sa', | ||
admin_pass => 'Pupp3t1@', | ||
} | ||
sqlserver::database{'#{DB_NAME}': | ||
instance => 'MSSQLSERVER', | ||
} | ||
MANIFEST | ||
|
||
apply_manifest_on(host, pp) do |r| | ||
expect(r.stderr).not_to match(/Error/i) | ||
end | ||
end | ||
|
||
context "server_url =>", {:testrail => ['89024', '89025', '89026', '89068', '89069']} do | ||
|
||
before(:all) do | ||
# Create new database | ||
@table_name = 'Tables_' + SecureRandom.hex(3) | ||
@query = "USE #{DB_NAME}; SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE table_name = '#{@table_name}';" | ||
|
||
ensure_sqlserver_database(host) | ||
end | ||
|
||
after(:all) do | ||
# remove the newly created instance | ||
ensure_sqlserver_database(host, 'absent') | ||
end | ||
|
||
it "Run a simple tsql command via sqlserver_tsql:" do | ||
pp = <<-MANIFEST | ||
sqlserver::config{'MSSQLSERVER': | ||
instance_name => 'MSSQLSERVER', | ||
admin_user => 'sa', | ||
admin_pass => 'Pupp3t1@', | ||
} | ||
sqlserver_tsql{'testsqlserver_tsql': | ||
instance => 'MSSQLSERVER', | ||
database => '#{DB_NAME}', | ||
command => "CREATE TABLE #{@table_name} (id INT, name VARCHAR(20), email VARCHAR(20));", | ||
} | ||
MANIFEST | ||
apply_manifest_on(host, pp) do |r| | ||
expect(r.stderr).not_to match(/Error/i) | ||
end | ||
|
||
puts "validate the result of tsql command and table #{@table_name} should be created:" | ||
run_sql_query(host, {:query => @query, :sql_admin_user => @admin_user, \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. '' not necessary see other multiline comment. |
||
:sql_admin_pass => @admin_pass, :expected_row_count => 1}) | ||
end | ||
|
||
it "Run sqlserver_tsql WITH onlyif is true:" do | ||
#Initilize a new table name: | ||
@table_name = 'Table_' + SecureRandom.hex(3) | ||
@query = "USE #{DB_NAME}; SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE table_name = '#{@table_name}';" | ||
pp = <<-MANIFEST | ||
sqlserver::config{'MSSQLSERVER': | ||
instance_name => 'MSSQLSERVER', | ||
admin_user => 'sa', | ||
admin_pass => 'Pupp3t1@', | ||
} | ||
sqlserver_tsql{'testsqlserver_tsql': | ||
instance => 'MSSQLSERVER', | ||
database => '#{DB_NAME}', | ||
command => "CREATE TABLE #{@table_name} (id INT, name VARCHAR(20), email VARCHAR(20));", | ||
onlyif => "IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES) < 10000" | ||
} | ||
MANIFEST | ||
|
||
apply_manifest_on(host, pp) do |r| | ||
expect(r.stderr).not_to match(/Error/i) | ||
end | ||
|
||
puts "Validate #{@table_name} is successfully created:" | ||
run_sql_query(host, {:query => @query, :sql_admin_user => @admin_user, \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. '' not necessary see other multiline comment. |
||
:sql_admin_pass => @admin_pass, :expected_row_count => 1}) | ||
end | ||
it "Run sqlserver_tsql WITH onlyif is false:" do | ||
#Initilize a new table name: | ||
@table_name = 'Table_' + SecureRandom.hex(3) | ||
@query = "USE #{DB_NAME}; SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE table_name = '#{@table_name}';" | ||
pp = <<-MANIFEST | ||
sqlserver::config{'MSSQLSERVER': | ||
instance_name => 'MSSQLSERVER', | ||
admin_user => 'sa', | ||
admin_pass => 'Pupp3t1@', | ||
} | ||
sqlserver_tsql{'testsqlserver_tsql': | ||
instance => 'MSSQLSERVER', | ||
database => '#{DB_NAME}', | ||
command => "CREATE TABLE #{@table_name} (id INT, name VARCHAR(20), email VARCHAR(20));", | ||
onlyif => "IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES) > 10000 | ||
THROW 5300, 'Too many tables', 10" | ||
} | ||
MANIFEST | ||
|
||
apply_manifest_on(host, pp) do |r| | ||
expect(r.stderr).not_to match(/Error/i) | ||
end | ||
|
||
puts "Validate #{@table_name} is NOT created:" | ||
run_sql_query(host, {:query => @query, :sql_admin_user => @admin_user, \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. '' not necessary see other multiline comment. |
||
:sql_admin_pass => @admin_pass, :expected_row_count => 0}) | ||
end | ||
|
||
it "Negative test: Run tsql with invalid command:" do | ||
pp = <<-MANIFEST | ||
sqlserver::config{'MSSQLSERVER': | ||
instance_name => 'MSSQLSERVER', | ||
admin_user => 'sa', | ||
admin_pass => 'Pupp3t1@', | ||
} | ||
sqlserver_tsql{'testsqlserver_tsql': | ||
instance => 'MSSQLSERVER', | ||
database => '#{DB_NAME}', | ||
command => "invalid-tsql-command", | ||
} | ||
MANIFEST | ||
apply_manifest_on(host, pp, {:acceptable_exit_codes => [0,1]}) do |r| | ||
expect(r.stderr).to match(/Error/i) | ||
end | ||
end | ||
|
||
it "Negative test: Run tsql with non-existing database:" do | ||
@table_name = 'Table_' + SecureRandom.hex(3) | ||
pp = <<-MANIFEST | ||
sqlserver::config{'MSSQLSERVER': | ||
instance_name => 'MSSQLSERVER', | ||
admin_user => 'sa', | ||
admin_pass => 'Pupp3t1@', | ||
} | ||
sqlserver_tsql{'testsqlserver_tsql': | ||
instance => 'MSSQLSERVER', | ||
database => 'Non-Existing-Database', | ||
command => "CREATE TABLE #{@table_name} (id INT, name VARCHAR(20), email VARCHAR(20));", | ||
} | ||
MANIFEST | ||
apply_manifest_on(host, pp, {:acceptable_exit_codes => [0,1]}) do |r| | ||
expect(r.stderr).to match(/Error/i) | ||
end | ||
end | ||
end | ||
end |
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.
Should this context be more descriptive? 'server_url =>' doesn't tell me anything about the tests contained in this block.