-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes: * It is possible to set the name of the manifest in case it is necessary renaming it. * It is possible to set the password related to the PG web service.
- Loading branch information
Showing
6 changed files
with
140 additions
and
41 deletions.
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
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
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,42 @@ | ||
require 'pg' | ||
|
||
class UnitTestsUtils::PostgreSQLClient | ||
attr_reader :args | ||
|
||
POSTGRESQL_PROPERTIES_PATH = '/instance_groups/name=pg/jobs/name=postgresql-ha/properties' | ||
|
||
def initialize(args) | ||
@args = args | ||
@args[:dbname] ||= 'area51' | ||
@args[:sslmode] ||= 'disable' | ||
end | ||
|
||
def self.create_from_manifest(manifest, host = nil) | ||
host = manifest.hostname unless host | ||
user = manifest.properties['postgresql-ha']['admin_credentials']['username'] | ||
password = manifest.properties['postgresql-ha']['admin_credentials']['password'] | ||
if manifest.properties("#{POSTGRESQL_PROPERTIES_PATH}/postgresql-ha/ssl?/enable") | ||
sslmode = "require" | ||
end | ||
|
||
self.new(host: host, user: user, password: password, sslmode: sslmode) | ||
end | ||
|
||
def ping | ||
logger.debug("* Creating ping with args: *#{args}*") | ||
return PG::Connection.ping(args) | ||
end | ||
|
||
def connect(extra_args = {}) | ||
args.merge!(extra_args) | ||
logger.debug("* Creating connection with args: *#{args}*") | ||
return PG::Connection.new(args) | ||
end | ||
|
||
def execute(sql, args = {}) | ||
conn = connect(args) | ||
return conn.exec(sql) | ||
ensure | ||
conn.close if !conn.nil? | ||
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
38 changes: 38 additions & 0 deletions
38
spec/lib/unit_tests_utils/postgresql_web_service_client_spec.rb
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,38 @@ | ||
require 'spec_helper' | ||
|
||
describe UnitTestsUtils::PGWebServiceClient do | ||
describe "#initialize" do | ||
let(:manifest_id) { 'manifest_id' } | ||
let(:manifest) do | ||
manifest_mocked = double('') | ||
allow(manifest_mocked).to receive(:name).and_return(manifest_id) | ||
manifest_mocked | ||
end | ||
subject(:pg_web_service_client) { UnitTestsUtils::PGWebServiceClient.new(manifest, pg_web_service_options) } | ||
|
||
context 'when there are not options' do | ||
let(:pg_web_service_options) { {} } | ||
|
||
specify do | ||
expect(pg_web_service_client.password).to eq UnitTestsUtils::PGWebServiceClient::DEFAULT_WEB_SERVICE_PASSWORD | ||
expect(pg_web_service_client.manifest_name).to eq manifest_id | ||
end | ||
end | ||
|
||
context 'when there are options' do | ||
let(:manifest_name) { 'manifest_name' } | ||
let(:password) { UnitTestsUtils::PGWebServiceClient::DEFAULT_WEB_SERVICE_PASSWORD } | ||
let(:pg_web_service_options) do | ||
{ | ||
new_manifest_name: manifest_name, | ||
pg_web_service_password: password | ||
} | ||
end | ||
|
||
specify do | ||
expect(pg_web_service_client.password).to eq password | ||
expect(pg_web_service_client.manifest_name).to eq manifest_name | ||
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