Skip to content

Commit 2d777f1

Browse files
Merge pull request #2003 from gooddata/mduf/drivers_it
test: driver integration tests
2 parents d1b6541 + 4d79402 commit 2d777f1

File tree

5 files changed

+322
-2
lines changed

5 files changed

+322
-2
lines changed

Dockerfile.jruby

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM jruby:9.4.1.0
22

33
MAINTAINER Tomas Korcak <[email protected]>
44

5-
RUN apt-get update && apt-get install -y curl make gcc git g++ python binutils-gold gnupg libstdc++6 cmake
5+
RUN apt-get update && apt-get install -y curl make gcc git g++ python binutils-gold gnupg libstdc++6 cmake maven
66

77
# Switch to directory with sources
88
WORKDIR /src
@@ -15,6 +15,18 @@ RUN gem update --system \
1515

1616
ADD . .
1717

18+
# build postgresql dependencies
19+
RUN mvn -f ci/postgresql/pom.xml clean install -P binary-packaging \
20+
&& cp -rf ci/postgresql/target/*.jar ./lib/gooddata/cloud_resources/postgresql/drivers/
21+
22+
# build mssql dependencies
23+
RUN mvn -f ci/mssql/pom.xml clean install -P binary-packaging \
24+
&& cp -rf ci/mssql/target/*.jar ./lib/gooddata/cloud_resources/mssql/drivers/
25+
26+
# build mysql dependencies
27+
RUN mvn -f ci/mysql/pom.xml clean install -P binary-packaging \
28+
&& cp -rf ci/mysql/target/*.jar ./lib/gooddata/cloud_resources/mysql/drivers/
29+
1830
# Import GoodData certificate to Java. This is needed for connection to ADS.
1931
# https://jira.intgdc.com/browse/TMA-300
2032
RUN keytool -importcert -alias gooddata-2008 -file "./data/2008.crt" -keystore $JAVA_HOME/lib/security/cacerts -trustcacerts -storepass 'changeit' -noprompt

ci/postgresql/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<dependency>
1313
<groupId>org.postgresql</groupId>
1414
<artifactId>postgresql</artifactId>
15-
<version>42.2.19</version>
15+
<version>42.5.0</version>
1616
</dependency>
1717
<dependency>
1818
<groupId>org.slf4j</groupId>
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
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# /Users/milandufek/dev/gooddata/gooddata-ruby/spec/integration/drivers/mysql_client_test.rb
2+
3+
require 'spec_helper'
4+
require 'gooddata/cloud_resources/mysql/mysql_client'
5+
require 'rspec'
6+
require 'csv'
7+
require 'benchmark'
8+
9+
describe GoodData::CloudResources::MysqlClient do
10+
before do
11+
@mysql_host = ENV['MYSQL_HOST'] || 'localhost'
12+
@mysql_port = ENV['MYSQL_PORT'] || 3306
13+
@mysql_database = ENV['MYSQL_DB'] || 'mysql'
14+
@mysql_user = ENV['MYSQL_USER'] || 'root'
15+
@mysql_password = ENV['MYSQL_SECRET'] || 'root'
16+
end
17+
18+
let(:valid_options) do
19+
{
20+
'mysql_client' => {
21+
'connection' => {
22+
'database' => @mysql_database,
23+
'schema' => 'public',
24+
'authentication' => {
25+
'basic' => {
26+
'userName' => @mysql_user,
27+
'password' => @mysql_password
28+
}
29+
},
30+
'sslMode' => 'prefer',
31+
'url' => "jdbc:mysql://#{@mysql_host}:#{@mysql_port}/#{@mysql_database}"
32+
}
33+
}
34+
}
35+
end
36+
37+
describe '.accept?' do
38+
it 'returns true for mysql type' do
39+
expect(GoodData::CloudResources::MysqlClient.accept?('mysql')).to be true
40+
end
41+
42+
it 'returns false for other types' do
43+
expect(GoodData::CloudResources::MysqlClient.accept?('postgresql')).to be false
44+
end
45+
end
46+
47+
describe '#initialize' do
48+
it 'raises an error if mysql_client is missing' do
49+
options = {}
50+
expect { GoodData::CloudResources::MysqlClient.new(options) }.to raise_error(RuntimeError, "Data Source needs a client to Mysql to be able to query the storage but 'mysql_client' is empty.")
51+
end
52+
53+
it 'raises an error if connection info is missing' do
54+
options = { 'mysql_client' => {} }
55+
expect { GoodData::CloudResources::MysqlClient.new(options) }.to raise_error(RuntimeError, 'Missing connection info for Mysql client')
56+
end
57+
58+
it 'raises an error if sslMode is invalid' do
59+
invalid_options = valid_options.dup
60+
invalid_options['mysql_client']['connection']['sslMode'] = 'invalid'
61+
expect { GoodData::CloudResources::MysqlClient.new(invalid_options) }.to raise_error(RuntimeError, 'SSL Mode should be prefer, require and verify-full')
62+
end
63+
64+
it 'initializes with valid options' do
65+
client = GoodData::CloudResources::MysqlClient.new(valid_options)
66+
expect(client).not_to be_nil
67+
end
68+
end
69+
70+
describe '#build_url' do
71+
it 'builds the correct URL' do
72+
client = GoodData::CloudResources::MysqlClient.new(valid_options)
73+
expected_url = "jdbc:mysql://#{@mysql_host}:#{@mysql_port}/#{@mysql_database}?&useSSL=true&requireSSL=false&verifyServerCertificate=false&useCursorFetch=true&enabledTLSProtocols=TLSv1.2"
74+
expect(client.send(:build_url, "jdbc:mysql://#{@mysql_host}:#{@mysql_port}")).to eq(expected_url)
75+
end
76+
end
77+
78+
describe '#connect' do
79+
it 'sets up the connection' do
80+
client = GoodData::CloudResources::MysqlClient.new(valid_options)
81+
client.connect
82+
expect(client.instance_variable_get(:@connection)).not_to be_nil
83+
end
84+
end
85+
86+
describe '#realize_query' do
87+
it 'executes the query and writes results to a CSV file' do
88+
client = GoodData::CloudResources::MysqlClient.new(valid_options)
89+
client.connect
90+
output_file = client.realize_query('SELECT 123;', {})
91+
expect(File).to exist(output_file)
92+
expect(File.read(output_file)).to include('123')
93+
File.delete(output_file)
94+
end
95+
end
96+
97+
describe '#fetch_size' do
98+
it 'returns the correct fetch size for MySQL' do
99+
client = GoodData::CloudResources::MysqlClient.new(valid_options)
100+
expect(client.fetch_size).to eq(GoodData::CloudResources::MysqlClient::MYSQL_FETCH_SIZE)
101+
end
102+
103+
it 'returns the correct fetch size for MongoDB BI Connector' do
104+
mongo_options = valid_options.dup
105+
mongo_options['mysql_client']['connection']['databaseType'] = GoodData::CloudResources::MysqlClient::MONGO_BI_TYPE
106+
client = GoodData::CloudResources::MysqlClient.new(mongo_options)
107+
expect(client.fetch_size).to eq(GoodData::CloudResources::MysqlClient::MONGO_BI_FETCH_SIZE)
108+
end
109+
end
110+
111+
describe '#get_ssl_mode' do
112+
it 'returns the correct SSL mode for prefer' do
113+
client = GoodData::CloudResources::MysqlClient.new(valid_options)
114+
expect(client.send(:get_ssl_mode, 'prefer')).to eq(GoodData::CloudResources::MysqlClient::PREFER)
115+
end
116+
117+
it 'returns the correct SSL mode for require' do
118+
client = GoodData::CloudResources::MysqlClient.new(valid_options)
119+
expect(client.send(:get_ssl_mode, 'require')).to eq(GoodData::CloudResources::MysqlClient::REQUIRE)
120+
end
121+
122+
it 'returns the correct SSL mode for verify-full' do
123+
client = GoodData::CloudResources::MysqlClient.new(valid_options)
124+
expect(client.send(:get_ssl_mode, 'verify-full')).to eq(GoodData::CloudResources::MysqlClient::VERIFY_FULL)
125+
end
126+
end
127+
128+
describe '#add_extended' do
129+
it 'returns the correct extended parameters for MongoDB BI Connector' do
130+
mongo_options = valid_options.dup
131+
mongo_options['mysql_client']['connection']['databaseType'] = GoodData::CloudResources::MysqlClient::MONGO_BI_TYPE
132+
client = GoodData::CloudResources::MysqlClient.new(mongo_options)
133+
expect(client.send(:add_extended)).to eq('&authenticationPlugins=org.mongodb.mongosql.auth.plugin.MongoSqlAuthenticationPlugin&useLocalTransactionState=true')
134+
end
135+
136+
it 'returns an empty string for MySQL' do
137+
client = GoodData::CloudResources::MysqlClient.new(valid_options)
138+
expect(client.send(:add_extended)).to eq('')
139+
end
140+
end
141+
end
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# spec/lib/gooddata/cloud_resources/postgresql/postgresql_client_spec.rb
2+
3+
require 'spec_helper'
4+
require 'gooddata/cloud_resources/postgresql/postgresql_client'
5+
require 'rspec'
6+
require 'csv'
7+
require 'benchmark'
8+
9+
describe GoodData::CloudResources::PostgresClient do
10+
before do
11+
@postresql_host = ENV['POSTGRES_HOST'] || 'localhost'
12+
@postresql_port = ENV['POSTGRES_PORT'] || 5432
13+
@postresql_database = ENV['POSTGRES_DB'] || 'postgres'
14+
@postgres_schema = ENV['POSTGRES_SCHEMA'] || 'public'
15+
@postresql_user = ENV['POSTGRES_USER'] || 'postgres'
16+
@postresql_password = ENV['POSTGRES_SECRET'] || 'postgres'
17+
end
18+
19+
let(:valid_options) do
20+
{
21+
'postgresql_client' => {
22+
'connection' => {
23+
'database' => @postresql_database,
24+
'schema' => @postgres_schema,
25+
'authentication' => {
26+
'basic' => {
27+
'userName' => @postresql_user,
28+
'password' => @postresql_password
29+
}
30+
},
31+
'sslMode' => 'prefer',
32+
'url' => "jdbc:postgresql://#{@postresql_host}:#{@postresql_port}/#{@postresql_database}"
33+
}
34+
}
35+
}
36+
end
37+
38+
describe '.accept?' do
39+
it 'returns true for postgresql type' do
40+
expect(GoodData::CloudResources::PostgresClient.accept?('postgresql')).to be true
41+
end
42+
43+
it 'returns false for other types' do
44+
expect(GoodData::CloudResources::PostgresClient.accept?('mysql')).to be false
45+
end
46+
end
47+
48+
describe '#initialize' do
49+
it 'raises an error if postgresql_client is missing' do
50+
options = {}
51+
expect { GoodData::CloudResources::PostgresClient.new(options) }.to raise_error(RuntimeError, "Data Source needs a client to Postgres to be able to query the storage but 'postgresql_client' is empty.")
52+
end
53+
54+
it 'raises an error if connection info is missing' do
55+
options = { 'postgresql_client' => {} }
56+
expect { GoodData::CloudResources::PostgresClient.new(options) }.to raise_error(RuntimeError, 'Missing connection info for Postgres client')
57+
end
58+
59+
it 'raises an error if sslMode is invalid' do
60+
invalid_options = valid_options.dup
61+
invalid_options['postgresql_client']['connection']['sslMode'] = 'invalid'
62+
expect { GoodData::CloudResources::PostgresClient.new(invalid_options) }.to raise_error(RuntimeError, 'SSL Mode should be prefer, require and verify-full')
63+
end
64+
65+
it 'initializes with valid options' do
66+
client = GoodData::CloudResources::PostgresClient.new(valid_options)
67+
expect(client).not_to be_nil
68+
end
69+
end
70+
71+
describe '#build_url' do
72+
it 'builds the correct URL' do
73+
client = GoodData::CloudResources::PostgresClient.new(valid_options)
74+
expected_url = "jdbc:postgresql://#{@postresql_host}:#{@postresql_port}/#{@postresql_database}?sslmode=prefer"
75+
expect(client.send(:build_url, "jdbc:postgresql://#{@postresql_host}:#{@postresql_port}")).to eq(expected_url)
76+
end
77+
end
78+
79+
describe '#connect' do
80+
it 'sets up the connection' do
81+
client = GoodData::CloudResources::PostgresClient.new(valid_options)
82+
client.connect
83+
expect(client.instance_variable_get(:@connection)).not_to be_nil
84+
end
85+
end
86+
87+
describe '#realize_query_version' do
88+
it 'executes the query with postgres version and writes results to a CSV file' do
89+
client = GoodData::CloudResources::PostgresClient.new(valid_options)
90+
client.connect
91+
output_file = client.realize_query('SELECT version();', {})
92+
expect(File).to exist(output_file)
93+
expect(File.read(output_file)).to include('PostgreSQL')
94+
File.delete(output_file)
95+
end
96+
end
97+
end

0 commit comments

Comments
 (0)