Skip to content

Commit

Permalink
add more specs
Browse files Browse the repository at this point in the history
  • Loading branch information
hirakiuc committed Apr 26, 2015
1 parent f2204d3 commit cf6ab41
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/ec2_meta/apis/2014_02_25/meta_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def macs(mac = nil)
when nil
fetch_macs
else
::Kernel.raise ArgumentError, 'require String or Integer, or nil.'
::Kernel.raise ::ArgumentError, 'require String or Integer, or nil.'
end
end

Expand Down
114 changes: 107 additions & 7 deletions spec/lib/ec2_meta/apis/2014_02_25/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,117 @@ def stub_notfound(path)
end

context 'with string' do
pending 'add spec'
let(:mac_addr) { 'xx:xx:xx:xx' }
it { expect(interfaces.macs(mac_addr)).not_to eq(nil) }
end

context 'with exist position' do
pending 'add spec'
context 'with integer' do
let(:expected) { "xx:xx:xx:xx/\nyy:yy:yy:yy/\n" }
before { stub('meta-data/network/interfaces/macs/', expected) }

context 'with exist position' do
it { expect(interfaces.macs(0)).not_to eq(nil) }
end

context 'with non-exist position' do
it { expect(interfaces.macs(100)).to eq(nil) }
end
end

context 'with non-exist position' do
pending 'add spec'
context 'with un-expected argument type' do
it { expect { interfaces.macs(key: 'value') }.to raise_error(ArgumentError) }
end

describe 'mac space' do
# ....
let(:mac_addr) { 'xx:xx:xx:xx' }
let(:mac) { interfaces.macs(mac_addr) }
let(:path_prefix) { "meta-data/network/interfaces/macs/#{mac_addr}" }

before { stub('meta-data/network/interfaces/macs/', "#{mac_addr}/\n") }

describe '#device_number' do
let(:expected) { '0' }
before { stub(path_prefix + '/device-number', expected) }
it { expect(mac.device_number).to eq(expected) }
end

describe '#ipv4_associations/public_ip' do
let(:expected) { '192.168.0.10' }
before { stub(path_prefix + '/ipv4-associations/192.168.30.10', expected) }
it { expect(mac.ipv4_associations('192.168.30.10')).to eq(expected) }
end

describe '#local_hostname' do
let(:expected) { 'host.local' }
before { stub(path_prefix + '/local-hostname', expected) }
it { expect(mac.local_hostname).to eq(expected) }
end

describe '#local_ipv4s' do
let(:expected) { "192.168.0.10\n" }
before { stub(path_prefix + '/local-ipv4s', expected) }
it { expect(mac.local_ipv4s).to eq(expected) }
end

describe '#mac' do
let(:expected) { 'xx:xx:xx:xx' }
before { stub(path_prefix + '/mac', expected) }
it { expect(mac.mac).to eq(expected) }
end

describe '#owner_id' do
let(:expected) { 'owner_id_xxx' }
before { stub(path_prefix + '/owner-id', expected) }
it { expect(mac.owner_id).to eq(expected) }
end

describe '#public_hostname' do
let(:expected) { 'host.public' }
before { stub(path_prefix + '/public-hostname', expected) }
it { expect(mac.public_hostname).to eq(expected) }
end

describe '#public_ipv4s' do
let(:expected) { "192.168.0.10\n" }
before { stub(path_prefix + '/public-ipv4s', expected) }
it { expect(mac.public_ipv4s).to eq(expected) }
end

describe '#security_groups' do
let(:expected) { "groupA\n" }
before { stub(path_prefix + '/security-groups', expected) }
it { expect(mac.security_groups).to eq(expected) }
end

describe '#security_group_ids' do
let(:expected) { "idxxxx\nidyyyy\n" }
before { stub(path_prefix + '/security-group-ids', expected) }
it { expect(mac.security_group_ids).to eq(expected) }
end

describe '#subnet_id' do
let(:expected) { 'subnet_id_xxx' }
before { stub(path_prefix + '/subnet-id', expected) }
it { expect(mac.subnet_id).to eq(expected) }
end

describe '#subnet_ipv4_cidr_block' do
let(:expected) { '192.168.0.0/24' }
before { stub(path_prefix + '/subnet-ipv4-cidr-block', expected) }
it { expect(mac.subnet_ipv4_cidr_block).to eq(expected) }
end

describe '#vpc_id' do
let(:expected) { 'vpc_id_xxx' }
before { stub(path_prefix + '/vpc-id', expected) }
it { expect(mac.vpc_id).to eq(expected) }
end

describe '#vpc_ipv4_cidr_block' do
let(:expected) { '192.168.0.0/24' }
before { stub(path_prefix + '/vpc-ipv4-cidr-block', expected) }
it { expect(mac.vpc_ipv4_cidr_block).to eq(expected) }
end
end
end
end
Expand Down Expand Up @@ -200,7 +298,9 @@ def stub_notfound(path)
end

describe 'public_keys space' do
pending 'add specs'
let(:expected) { 'ssh-rsa AAA.........' }
before { stub('meta-data/public-keys/0/openssh-key', expected) }
it { expect(meta_data.public_keys(0).openssh_key).to eq(expected) }
end

describe '#ramdisk_id' do
Expand Down
5 changes: 4 additions & 1 deletion spec/lib/ec2_meta/fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@
end

context 'when unexpected eror raised' do
before { Net::HTTP.any_instance.stub(:get).and_raise(ArgumentError) }
before do
expect_any_instance_of(Net::HTTP).to \
receive(:get).and_raise(ArgumentError)
end
it { expect { subject }.to raise_error(ArgumentError) }
end
end
Expand Down

0 comments on commit cf6ab41

Please sign in to comment.