This repository has been archived by the owner on Dec 31, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Igor Rzegocki
committed
Apr 23, 2016
1 parent
05e3a75
commit 72d4b9f
Showing
8 changed files
with
234 additions
and
153 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
module Drivers | ||
module Db | ||
class Mysql < Base | ||
adapter :mysql2 | ||
allowed_engines :mysql, :mysql2 | ||
packages debian: 'libmysqlclient-dev', rhel: 'mysql-devel' | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
RSpec.shared_examples 'db parameters and connection' do |rdbms, options = {}| | ||
it 'receives and exposes app, node and database bag' do | ||
driver = described_class.new(aws_opsworks_app, node, rds: aws_opsworks_rds_db_instance(engine: rdbms)) | ||
|
||
expect(driver.app).to eq aws_opsworks_app | ||
expect(driver.node).to eq node | ||
expect(driver.options[:rds]).to eq aws_opsworks_rds_db_instance(engine: rdbms) | ||
end | ||
|
||
it 'raises error when no rds is present' do | ||
expect do | ||
described_class.new(aws_opsworks_app, node, dummy_option: true).out | ||
end.to raise_error ArgumentError, ':rds option is not set.' | ||
end | ||
|
||
context 'connection data' do | ||
it 'taken from engine' do | ||
item = described_class.new( | ||
aws_opsworks_app, | ||
node(deploy: { dummy_project: { database: { adapter: rdbms } } }), | ||
rds: aws_opsworks_rds_db_instance(engine: rdbms) | ||
) | ||
expect(item.out).to eq( | ||
encoding: 'utf8', | ||
reconnect: true, | ||
adapter: options[:adapter] || rdbms, | ||
username: 'dbuser', | ||
password: '03c1bc98cdd5eb2f9c75', | ||
host: 'dummy-project.c298jfowejf.us-west-2.rds.amazon.com', | ||
database: 'dummydb' | ||
) | ||
end | ||
|
||
it 'taken from adapter' do | ||
item = described_class.new( | ||
aws_opsworks_app, | ||
node(deploy: { dummy_project: { database: { adapter: rdbms } } }), | ||
rds: aws_opsworks_rds_db_instance(engine: nil) | ||
) | ||
expect(item.out).to eq( | ||
encoding: 'utf8', | ||
reconnect: true, | ||
adapter: options[:adapter] || rdbms, | ||
host: 'localhost', | ||
database: 'dummydb' | ||
) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# frozen_string_literal: true | ||
RSpec.shared_examples 'db validate adapter and engine' do |rdbms| | ||
context "#{rdbms}: validate adapter and engine" do | ||
it 'adapter = missing, engine = missing' do | ||
expect do | ||
described_class.new( | ||
aws_opsworks_app, node(deploy: { dummy_project: {} }), rds: aws_opsworks_rds_db_instance(engine: nil) | ||
).out | ||
end.to raise_error ArgumentError, | ||
"Missing :app or :node engine, expected #{described_class.allowed_engines.inspect}." | ||
end | ||
|
||
it 'adapter = missing, engine = wrong' do | ||
expect do | ||
described_class.new( | ||
aws_opsworks_app, node(deploy: { dummy_project: {} }), rds: aws_opsworks_rds_db_instance(engine: 'wrong') | ||
).out | ||
end.to raise_error ArgumentError, | ||
"Incorrect :app engine, expected #{described_class.allowed_engines.inspect}, got 'wrong'." | ||
end | ||
|
||
it 'adapter = missing, engine = correct' do | ||
expect do | ||
described_class.new( | ||
aws_opsworks_app, node(deploy: { dummy_project: {} }), rds: aws_opsworks_rds_db_instance(engine: rdbms) | ||
).out | ||
end.not_to raise_error | ||
end | ||
|
||
it 'adapter = wrong, engine = missing' do | ||
expect do | ||
described_class.new( | ||
aws_opsworks_app, | ||
node(deploy: { dummy_project: { database: { adapter: 'wrong' } } }), | ||
rds: aws_opsworks_rds_db_instance(engine: nil) | ||
).out | ||
end.to raise_error ArgumentError, | ||
"Incorrect :node engine, expected #{described_class.allowed_engines.inspect}, got 'wrong'." | ||
end | ||
|
||
it 'adapter = wrong, engine = wrong' do | ||
expect do | ||
described_class.new( | ||
aws_opsworks_app, | ||
node(deploy: { dummy_project: { database: { adapter: 'wrong' } } }), | ||
rds: aws_opsworks_rds_db_instance(engine: 'wrong') | ||
).out | ||
end.to raise_error ArgumentError, | ||
"Incorrect :app engine, expected #{described_class.allowed_engines.inspect}, got 'wrong'." | ||
end | ||
|
||
it 'adapter = wrong, engine = correct' do | ||
expect do | ||
described_class.new( | ||
aws_opsworks_app, | ||
node(deploy: { dummy_project: { database: { adapter: 'wrong' } } }), | ||
rds: aws_opsworks_rds_db_instance(engine: rdbms) | ||
).out | ||
end.not_to raise_error | ||
end | ||
|
||
it 'adapter = correct, engine = missing' do | ||
expect do | ||
described_class.new( | ||
aws_opsworks_app, | ||
node(deploy: { dummy_project: { database: { adapter: rdbms } } }), | ||
rds: aws_opsworks_rds_db_instance(engine: nil) | ||
).out | ||
end.not_to raise_error | ||
end | ||
|
||
it 'adapter = correct, engine = wrong' do | ||
expect do | ||
described_class.new( | ||
aws_opsworks_app, | ||
node(deploy: { dummy_project: { database: { adapter: rdbms } } }), | ||
rds: aws_opsworks_rds_db_instance(engine: 'wrong') | ||
).out | ||
end.to raise_error ArgumentError, | ||
"Incorrect :app engine, expected #{described_class.allowed_engines.inspect}, got 'wrong'." | ||
end | ||
|
||
it 'adapter = correct, engine = correct' do | ||
expect do | ||
described_class.new( | ||
aws_opsworks_app, | ||
node(deploy: { dummy_project: { database: { adapter: rdbms } } }), | ||
rds: aws_opsworks_rds_db_instance(engine: rdbms) | ||
).out | ||
end.not_to raise_error | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
require 'spec_helper' | ||
require 'unit/examples/db_validate_adapter_and_engine' | ||
require 'unit/examples/db_parameters_and_connection' | ||
|
||
describe Drivers::Db::Mysql do | ||
include_examples 'db validate adapter and engine', 'mysql' | ||
include_examples 'db parameters and connection', 'mysql', adapter: 'mysql2' | ||
end |
Oops, something went wrong.