Skip to content

Commit eb1994b

Browse files
committed
test: integration tests for mssql driver
JIRA: GRIF-15
1 parent df19d9c commit eb1994b

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
require 'spec_helper'
2+
require 'gooddata/cloud_resources/mssql/mssql_client'
3+
require 'rspec'
4+
5+
describe GoodData::CloudResources::MSSQLClient do
6+
before do
7+
@mssql_host = ENV['MSSQL_HOST'] || 'localhost'
8+
@mssql_port = ENV['MSSQL_PORT'] || 1433
9+
@mssql_database = ENV['MSSQL_DB'] || 'master'
10+
@mssql_user = ENV['MSSQL_USER'] || 'sa'
11+
@mssql_password = ENV['MSSQL_PASSWORD'] || 'Password123'
12+
end
13+
14+
let(:valid_options) do
15+
{
16+
'mssql_client' => {
17+
'connection' => {
18+
'database' => @mssql_database,
19+
'schema' => 'dbo',
20+
'authentication' => {
21+
'basic' => {
22+
'userName' => @mssql_user,
23+
'password' => @mssql_password
24+
}
25+
},
26+
'sslMode' => 'prefer',
27+
'url' => "jdbc:sqlserver://#{@mssql_host}:#{@mssql_port}"
28+
}
29+
}
30+
}
31+
end
32+
33+
describe '.accept?' do
34+
it 'returns true for mssql type' do
35+
expect(GoodData::CloudResources::MSSQLClient.accept?('mssql')).to be true
36+
end
37+
38+
it 'returns false for other types' do
39+
expect(GoodData::CloudResources::MSSQLClient.accept?('mysql')). to be false
40+
end
41+
end
42+
43+
describe '#build_connection_string' do
44+
it 'builds a valid connection string' do
45+
client = GoodData::CloudResources::MSSQLClient.new(valid_options)
46+
connection_string = client.send(:build_connection_string)
47+
expect(connection_string).to eq("jdbc:sqlserver://#{@mssql_host}:#{@mssql_port};database=#{@mssql_database};"\
48+
"encrypt=false;trustServerCertificate=false;loginTimeout=30;")
49+
end
50+
end
51+
52+
describe '#initialize' do
53+
it 'raises an error if mssql_client is missing' do
54+
expect { GoodData::CloudResources::MSSQLClient.new({}) }.to raise_error(RuntimeError, "Data Source needs a client to MSSQL to be able to query the storage but 'mssql_client' is empty.")
55+
end
56+
57+
it 'initializes with valid options' do
58+
client = GoodData::CloudResources::MSSQLClient.new(valid_options)
59+
expect(client).to be_an_instance_of(GoodData::CloudResources::MSSQLClient)
60+
end
61+
62+
it 'connects to SQL Server and selects the version' do
63+
client = GoodData::CloudResources::MSSQLClient.new(valid_options)
64+
version_csv = client.realize_query('SELECT @@VERSION', nil)
65+
expect(File).to exist(version_csv)
66+
expect(File.read(version_csv)).to include('Microsoft SQL Server')
67+
File.delete(version_csv)
68+
end
69+
end
70+
end

0 commit comments

Comments
 (0)