spec/metadata_spec.rb in engineyard-metadata-0.1.2 vs spec/metadata_spec.rb in engineyard-metadata-0.2.0

- old
+ new

@@ -1,227 +1,231 @@ require 'spec_helper' shared_examples_for "it does in all execution environments" do it 'get the database username' do - EY::Metadata.database_username.should == 'FAKE_SSH_USERNAME' + EY.metadata.database_username.should == 'deploy' end it 'get the database name' do - EY::Metadata.database_name.should == 'FAKE_APP_NAME' + EY.metadata.database_name.should == 'cm1_certified_blue' end it 'get the database host' do - EY::Metadata.database_host.should == 'FAKE_DB_MASTER_PUBLIC_HOSTNAME' + EY.metadata.database_host.should == 'ec2-67-202-19-255.compute-1.amazonaws.com' end it 'get the ssh username' do - EY::Metadata.ssh_username.should == 'FAKE_SSH_USERNAME' + EY.metadata.ssh_username.should == 'deploy' end it 'get the app server hostnames' do - EY::Metadata.app_servers.should == [ 'app_1.compute-1.amazonaws.com' , 'app_master.compute-1.amazonaws.com' ] + EY.metadata.app_servers.should == ["ec2-174-129-212-130.compute-1.amazonaws.com"] end it 'get the db server hostnames' do - EY::Metadata.db_servers.should == [ 'FAKE_DB_MASTER_PUBLIC_HOSTNAME', 'db_slave_1.compute-1.amazonaws.com' ] + EY.metadata.db_servers.should == ["ec2-67-202-19-255.compute-1.amazonaws.com"] end it 'get the utilities hostnames' do - EY::Metadata.utilities.should == [ 'FAKE_UTIL_1_PUBLIC_HOSTNAME' ] + EY.metadata.utilities.should == [] end it 'get the app master hostname' do - EY::Metadata.app_master.should == 'app_master.compute-1.amazonaws.com' + EY.metadata.app_master.should == 'ec2-174-129-212-130.compute-1.amazonaws.com' end it 'get the db master hostname' do - EY::Metadata.db_master.should == 'FAKE_DB_MASTER_PUBLIC_HOSTNAME' + EY.metadata.db_master.should == 'ec2-67-202-19-255.compute-1.amazonaws.com' end it 'get the db slave hostnames' do - EY::Metadata.db_slaves.should == [ 'db_slave_1.compute-1.amazonaws.com' ] + EY.metadata.db_slaves.should == [] end it 'get the app slave hostnames' do - EY::Metadata.app_slaves.should == [ 'app_1.compute-1.amazonaws.com' ] + EY.metadata.app_slaves.should == [] end it 'get the solo hostname' do - EY::Metadata.solo.should == nil + EY.metadata.solo.should == nil end it 'get the environment name' do - EY::Metadata.environment_name.should == 'FAKE_ENVIRONMENT_NAME' + EY.metadata.environment_name.should == 'cm1_production_blue' end it 'get the stack name' do - EY::Metadata.stack_name.should == 'FAKE_STACK_NAME' + EY.metadata.stack_name.should == 'nginx_unicorn' end it 'get the repository URI' do - EY::Metadata.repository_uri.should == 'FAKE_REPOSITORY_URI' + EY.metadata.repository_uri.should == 'git@github.com:brighterplanet/cm1.git' end it 'gets the app name' do - EY::Metadata.app_name.should == 'FAKE_APP_NAME' + EY.metadata.app_name.should == 'cm1_certified_blue' end it 'gets the current path' do - EY::Metadata.current_path.should == '/data/FAKE_APP_NAME/current' + EY.metadata.current_path.should == '/data/cm1_certified_blue/current' end it 'gets the shared path' do - EY::Metadata.shared_path.should == '/data/FAKE_APP_NAME/shared' + EY.metadata.shared_path.should == '/data/cm1_certified_blue/shared' end it 'gets helpful ssh aliases' do - EY::Metadata.ssh_aliases.should =~ /Host FAKE_ENVIRONMENT_NAME-app_master\n Hostname app_master.compute-1.amazonaws.com/ + EY.metadata.ssh_aliases.should =~ /Host cm1_production_blue-app_master\n Hostname ec2-174-129-212-130.compute-1.amazonaws.com/ end end shared_examples_for "it's executing outside the cloud" do it 'gets the list of all environment names' do - EY::Metadata.environment_names.should == [ 'WRONG_ENVIRONMENT_NAME', 'FAKE_ENVIRONMENT_NAME' ] + EY.metadata.environment_names.should == ["app1_production", "wlpf1_production", "data1_production", "cm1_production_red", "cm1_production_blue"] end it 'not get the present instance ID' do lambda { - EY::Metadata.present_instance_id + EY.metadata.present_instance_id }.should raise_error(EY::Metadata::CannotGetFromHere) end it 'not get the present instance role (as a string)' do lambda { - EY::Metadata.present_instance_role + EY.metadata.present_instance_role }.should raise_error(EY::Metadata::CannotGetFromHere) end it 'not get the present public hostname' do lambda { - EY::Metadata.present_public_hostname + EY.metadata.present_public_hostname }.should raise_error(EY::Metadata::CannotGetFromHere) end it 'not get the present security group' do lambda { - EY::Metadata.present_security_group + EY.metadata.present_security_group }.should raise_error(EY::Metadata::CannotGetFromHere) end it 'not get the database password' do lambda { - EY::Metadata.database_password + EY.metadata.database_password }.should raise_error(EY::Metadata::CannotGetFromHere) end it 'not get the ssh password' do lambda { - EY::Metadata.ssh_password + EY.metadata.ssh_password }.should raise_error(EY::Metadata::CannotGetFromHere) end it 'not get the mysql command' do lambda { - EY::Metadata.mysql_command + EY.metadata.mysql_command }.should raise_error(EY::Metadata::CannotGetFromHere) end it 'not get the mysqldump command' do lambda { - EY::Metadata.mysqldump_command + EY.metadata.mysqldump_command }.should raise_error(EY::Metadata::CannotGetFromHere) end - - it 'get the raw EngineYard Cloud API data' do - EY::Metadata.engine_yard_cloud_api.data.should be_a(Hash) - end end shared_examples_for "it's executing inside the cloud" do it 'not get the list of all environment names' do lambda { - EY::Metadata.environment_names + EY.metadata.environment_names }.should raise_error(EY::Metadata::CannotGetFromHere) end it 'get the present instance ID' do - EY::Metadata.present_instance_id.should == PRESENT_INSTANCE_ID + EY.metadata.present_instance_id.should == FAKE_INSTANCE_ID end it 'get the present instance role (as a string)' do - EY::Metadata.present_instance_role.should == 'app_master' + EY.metadata.present_instance_role.should == 'app_master' end it 'get the present public hostname' do - EY::Metadata.present_public_hostname.should == PRESENT_PUBLIC_HOSTNAME + EY.metadata.present_public_hostname.should == 'ec2-174-129-212-130.compute-1.amazonaws.com' end it 'get the present security group' do - EY::Metadata.present_security_group.should == PRESENT_SECURITY_GROUP + EY.metadata.present_security_group.should == FAKE_SECURITY_GROUP end it 'get the database password' do - EY::Metadata.database_password.should == 'USERS-0-PASSWORD' + EY.metadata.database_password.should == 'USERS-0-PASSWORD' end it 'get the ssh password' do - EY::Metadata.ssh_password.should == 'SSH-PASSWORD' + EY.metadata.ssh_password.should == 'USERS-0-PASSWORD' end it 'get the mysql command' do - EY::Metadata.mysql_command.should =~ %r{mysql -h FAKE_DB_MASTER_PUBLIC_HOSTNAME -u FAKE_SSH_USERNAME -pUSERS-0-PASSWORD FAKE_APP_NAME} + EY.metadata.mysql_command.should =~ %r{mysql -h ec2-67-202-19-255.compute-1.amazonaws.com -u deploy -pUSERS-0-PASSWORD cm1_certified_blue} end it 'get the mysqldump command' do - EY::Metadata.mysqldump_command.should =~ %r{mysqldump -h FAKE_DB_MASTER_PUBLIC_HOSTNAME -u FAKE_SSH_USERNAME -pUSERS-0-PASSWORD FAKE_APP_NAME} + EY.metadata.mysqldump_command.should =~ %r{mysqldump -h ec2-67-202-19-255.compute-1.amazonaws.com -u deploy -pUSERS-0-PASSWORD cm1_certified_blue} end end -describe 'EY::Metadata' do +describe 'EY.metadata' do after do stop_pretending end describe "being executed on an EngineYard AppCloud (i.e. Amazon EC2) instance" do before do pretend_we_are_on_an_engineyard_appcloud_ec2_instance - EY::Metadata.reload + EY.metadata.reload + EY.metadata.app_name = 'cm1_certified_blue' end it_should_behave_like "it does in all execution environments" it_should_behave_like "it's executing inside the cloud" end describe "being executed from a developer/administrator's local machine" do before do pretend_we_are_on_a_developer_machine - EY::Metadata.reload - EY::Metadata.clear + EY.metadata.reload + EY.metadata.instance_variables.each do |ivar_name| + EY.metadata.instance_variable_set ivar_name, nil + end ENV.delete 'EY_CLOUD_TOKEN' ENV.delete 'EY_ENVIRONMENT_NAME' + ENV.delete 'EY_APP_NAME' + EY.metadata.app_name = 'cm1_certified_blue' end describe "controlled with environment variables" do before do + EY.metadata.instance_variables.each do |ivar_name| + EY.metadata.instance_variable_set ivar_name, nil + end ENV['EY_CLOUD_TOKEN'] = FAKE_CLOUD_TOKEN + 'aaa' - ENV['EY_ENVIRONMENT_NAME'] = FAKE_ENVIRONMENT_NAME - EY::Metadata.ey_cloud_token.should == FAKE_CLOUD_TOKEN + 'aaa' # sanity check + ENV['EY_APP_NAME'] = 'cm1_certified_blue' + EY.metadata.ey_cloud_token.should == FAKE_CLOUD_TOKEN + 'aaa' # sanity check end it_should_behave_like "it does in all execution environments" it_should_behave_like "it's executing outside the cloud" end describe "controlled with attr writers" do before do - EY::Metadata.ey_cloud_token = FAKE_CLOUD_TOKEN + 'bbb' - EY::Metadata.environment_name = FAKE_ENVIRONMENT_NAME - EY::Metadata.ey_cloud_token.should == FAKE_CLOUD_TOKEN + 'bbb' # sanity check + EY.metadata.ey_cloud_token = FAKE_CLOUD_TOKEN + 'bbb' + EY.metadata.app_name = 'cm1_certified_blue' + EY.metadata.ey_cloud_token.should == FAKE_CLOUD_TOKEN + 'bbb' # sanity check end it_should_behave_like "it does in all execution environments" it_should_behave_like "it's executing outside the cloud" end describe "depending on .eyrc" do before do - File.open(EY::Metadata.eyrc_path, 'w') { |f| f.write({'api_token' => FAKE_CLOUD_TOKEN + 'ccc'}.to_yaml) } - EY::Metadata.environment_name = FAKE_ENVIRONMENT_NAME - EY::Metadata.ey_cloud_token.should == FAKE_CLOUD_TOKEN + 'ccc' # sanity check + File.open(EY.metadata.eyrc_path, 'w') { |f| f.write({'api_token' => FAKE_CLOUD_TOKEN + 'ccc'}.to_yaml) } + EY.metadata.environment_name = 'cm1_production_blue' + EY.metadata.ey_cloud_token.should == FAKE_CLOUD_TOKEN + 'ccc' # sanity check end it_should_behave_like "it does in all execution environments" it_should_behave_like "it's executing outside the cloud" end end