Skip to content

Commit

Permalink
Merge pull request #58 from ClogenyTechnologies/sid-fix-rspec-tests
Browse files Browse the repository at this point in the history
Fix spec tests
  • Loading branch information
Nimisha Sharad committed Apr 6, 2015
2 parents 114817f + ec9c8ce commit 547402b
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 37 deletions.
17 changes: 12 additions & 5 deletions spec/chef/knife/google_disk_create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,22 @@

it "#run should invoke compute api to create a disk" do
zones = double(Google::Compute::ListableResourceCollection)
zones.should_receive(:get).
expect(zones).to receive(:get).
with(stored_zone.name).and_return(stored_zone)
disks = double(Google::Compute::CreatableResourceCollection)
disks.should_receive(:create).
with(:name => stored_disk.name, :sizeGb => 10, :zone => stored_zone.name).
expect(disks).to receive(:create).
with(:name => stored_disk.name, :sizeGb => 10, :zone => stored_zone.name,:type=>"").
and_return(stored_zone_operation)
client = double(Google::Compute::Client, :zones => zones, :disks => disks)
Google::Compute::Client.stub(:from_json).and_return(client)
disk_type = double(Google::Compute::CreatableResourceCollection)
d_type = Object.new
d_type.define_singleton_method(:self_link){""}
expect(disk_type).to receive(:get).
with(:name => 'pd-ssd', :zone => stored_zone.name).
and_return(d_type)
client = double(Google::Compute::Client, :zones => zones, :disks => disks, :disk_types => disk_type)
allow(Google::Compute::Client).to receive(:from_json).and_return(client)
knife_plugin.config[:disk_size] = 10
knife_plugin.config[:disk_type] = 'pd-ssd'
knife_plugin.run
end
end
8 changes: 4 additions & 4 deletions spec/chef/knife/google_disk_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@

it "should enlist all the GCE disks when run invoked" do
zones = double(Google::Compute::ListableResourceCollection)
zones.should_receive(:get).with(stored_zone.name).
expect(zones).to receive(:get).with(stored_zone.name).
and_return(stored_zone)
disks = double(Google::Compute::ListableResourceCollection)
disks.should_receive(:list).with(:zone => stored_zone.name).
expect(disks).to receive(:list).with(:zone => stored_zone.name).
and_return([stored_disk])

client = double(Google::Compute::Client, :disks => disks, :zones => zones)
Google::Compute::Client.stub(:from_json).and_return(client)
$stdout.should_receive(:write).with(kind_of(String))
allow(Google::Compute::Client).to receive(:from_json).and_return(client)
expect(knife_plugin.ui).to receive(:info)
knife_plugin.run
end
end
2 changes: 1 addition & 1 deletion spec/chef/knife/google_region_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
and_return(client)
client.should_receive(:regions).
and_return(double("region-collection", :list => [stored_region]))
$stdout.should_receive(:write).with(kind_of(String))
expect(knife_plugin.ui).to receive(:info)
knife_plugin.run
end
end
8 changes: 6 additions & 2 deletions spec/chef/knife/google_server_create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def setup(additional_disk=false)
networks = double(Google::Compute::ListableResourceCollection)
networks.should_receive(:get).with(stored_network.name).
and_return(stored_network)

disk_params = [{
"boot" => true,
"diskType"=> "https://www.googleapis.com/compute/v1/projects/mock-project/zones/mock-zone/diskTypes/pd-standard",
"type" => "PERSISTENT",
"mode" => "READ_WRITE",
"deviceName" => "",
Expand All @@ -75,7 +75,7 @@ def setup(additional_disk=false)
:name => stored_instance.name,
:zone => stored_zone.name,
:machineType => stored_machine_type.self_link,
:image => stored_image.self_link,
# :image => stored_image.self_link,
:disks => disk_params,
:networkInterfaces => [{
"network" => stored_network.self_link,
Expand All @@ -92,6 +92,7 @@ def setup(additional_disk=false)
:scheduling=>{
"automaticRestart" => "false",
"onHostMaintenance" => "TERMINATE"},
:canIpForward=>false,
:metadata => {"items" => []},
:tags => {"items" => []}}).and_return(stored_zone_operation)

Expand All @@ -117,6 +118,7 @@ def setup(additional_disk=false)
knife_plugin.config[:service_account_name]='123845678986@project.gserviceaccount.com'
knife_plugin.config[:boot_disk_size]='10'
knife_plugin.config[:metadata]=[]
knife_plugin.config[:metadata_from_file]=[]
knife_plugin.config[:tags]=[]
knife_plugin.config[:public_ip]='EPHEMERAL'
knife_plugin.ui.stub(:info)
Expand All @@ -142,6 +144,7 @@ def setup(additional_disk=false)
knife_plugin.config[:service_account_name]='123845678986@project.gserviceaccount.com'
knife_plugin.config[:boot_disk_size]='10'
knife_plugin.config[:metadata]=[]
knife_plugin.config[:metadata_from_file]=[]
knife_plugin.config[:tags]=[]
knife_plugin.config[:public_ip]='EPHEMERAL'
knife_plugin.ui.stub(:info)
Expand All @@ -165,6 +168,7 @@ def setup(additional_disk=false)
knife_plugin.config[:service_account_name]='123845678986@project.gserviceaccount.com'
knife_plugin.config[:boot_disk_size]='10'
knife_plugin.config[:metadata]=[]
knife_plugin.config[:metadata_from_file]=[]
knife_plugin.config[:tags]=[]
knife_plugin.config[:public_ip]='EPHEMERAL'
knife_plugin.ui.stub(:info)
Expand Down
2 changes: 1 addition & 1 deletion spec/chef/knife/google_zone_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
and_return(client)
client.should_receive(:zones).
and_return(double("zone-collection", :list => [stored_zone]))
$stdout.should_receive(:write).with(kind_of(String))
expect(knife_plugin.ui).to receive(:info)
knife_plugin.run
end
end
3 changes: 2 additions & 1 deletion spec/data/disk.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"options":"",
"status":"READY",
"sourceSnapshot":"",
"sourceSnapshotId":""
"sourceSnapshotId":"",
"type":"disk"
}
26 changes: 13 additions & 13 deletions spec/google/compute/disk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,66 +50,66 @@
# end

it "#get should return an individual disk by passing a hash with name key also" do
@mock_api_client.should_receive(:execute).
expect(@mock_api_client).to receive(:execute).
with(:api_method => mock_compute.disks.get,
:parameters => {"disk" => "mock-disk", :project => "mock-project", :zone => "mock-zone"},:body_object => nil).
and_return(mock_response(Google::Compute::Disk))

disk = client.disks.get(:name => 'mock-disk', :zone => "mock-zone")
disk.should be_a_kind_of Google::Compute::Disk
disk.name.should eq('mock-disk')
expect(disk).to be_a_kind_of Google::Compute::Disk
expect(disk.name).to eq('mock-disk')
end

it "#list should return an array of disks" do
@mock_api_client.should_receive(:execute).
expect(@mock_api_client).to receive(:execute).
with(:api_method => mock_compute.disks.list,
:parameters => {:project => "mock-project", :zone => "mock-zone"},:body_object => nil).
and_return(mock_response(Google::Compute::Disk, true))
disks = client.disks.list(:zone => "mock-zone")
disks.all?{|disk| disk.is_a?(Google::Compute::Disk)}.should be_true
expect(disks.all?{|disk| disk.is_a?(Google::Compute::Disk)}).to be true
end

it "#create should create a new disk" do
#zone = 'https://www.googleapis.com/compute/v1/projects/mock-project/zones/mock-zone'
zone = 'mock-zone'
@mock_api_client.should_receive(:execute).
expect(@mock_api_client).to receive(:execute).
with(:api_method => mock_compute.disks.insert,
:parameters => {:project => "mock-project", :zone => "mock-zone"},
:body_object => {:name => "xxx", :sizeGb => 2, :zone => "mock-zone"}).
and_return(mock_response(Google::Compute::ZoneOperation))
o = client.disks.create(:name => 'xxx', :sizeGb => 2, :zone => zone)
o.should be_a_kind_of Google::Compute::ZoneOperation
expect(o).to be_a_kind_of Google::Compute::ZoneOperation
end

it "#insert should create a new disk also" do
#zone = 'https://www.googleapis.com/compute/v1/projects/mock-project/zones/mock-zone'
zone = 'mock-zone'
@mock_api_client.should_receive(:execute).
expect(@mock_api_client).to receive(:execute).
with(:api_method => mock_compute.disks.insert,
:parameters => {:project => "mock-project", :zone => "mock-zone"},
:body_object => {:name => "xxx", :sizeGb => 2, :zone => "mock-zone"}).
and_return(mock_response(Google::Compute::ZoneOperation))
o = client.disks.insert(:name => 'xxx', :sizeGb => 2, :zone => zone)
o.should be_a_kind_of Google::Compute::ZoneOperation
expect(o).to be_a_kind_of Google::Compute::ZoneOperation
end

it "#delete should delete an existing disk" do
@mock_api_client.should_receive(:execute).
expect(@mock_api_client).to receive(:execute).
with(:api_method => mock_compute.disks.delete,
:parameters => {:project => "mock-project","disk" => "mock-disk", :zone => "mock-zone"},:body_object => nil).
and_return(mock_response(Google::Compute::ZoneOperation))
o = client.disks.delete("disk" => "mock-disk", :zone => "mock-zone")
o.should be_a_kind_of Google::Compute::ZoneOperation
expect(o).to be_a_kind_of Google::Compute::ZoneOperation
end

it "#createSnapshot should create a new snapshot" do
zone = 'mock-zone'
disk = 'https://www.googleapis.com/compute/v1/projects/mock-project/disks/mock-disk'
@mock_api_client.should_receive(:execute).
expect(@mock_api_client).to receive(:execute).
with(:api_method => mock_compute.disks.create_snapshot,
:parameters => {:project => "mock-project", :zone => zone, :disk => disk}, :body_object => nil).
and_return(mock_response(Google::Compute::ZoneOperation))
o = client.disks.create_snapshot(:project => "mock-project", :zone => zone, :disk => disk)
o.should be_a_kind_of Google::Compute::ZoneOperation
expect(o).to be_a_kind_of Google::Compute::ZoneOperation
end
end
2 changes: 1 addition & 1 deletion spec/google/compute/firewall_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
and_return(mock_response(Google::Compute::Firewall, true))
fws = client.firewalls.list
fws.should_not be_empty
fws.all?{|f| f.is_a?(Google::Compute::Firewall)}.should be_true
expect(fws.all?{|f| f.is_a?(Google::Compute::Firewall)}).to be_truthy
end

it '#create should create a new firewall' do
Expand Down
2 changes: 1 addition & 1 deletion spec/google/compute/global_operation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

operations = client.globalOperations.list
operations.should_not be_empty
operations.all?{|o| o.is_a?(Google::Compute::GlobalOperation)}.should be_true
expect(operations.all?{|o| o.is_a?(Google::Compute::GlobalOperation)}).to be_truthy
end

it '#get should return an individual global operation' do
Expand Down
2 changes: 1 addition & 1 deletion spec/google/compute/image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
and_return(mock_response(Google::Compute::Image, true))
images = client.images.list
images.should_not be_empty
images.all?{|i| i.is_a?(Google::Compute::Image)}.should be_true
expect(images.all?{|i| i.is_a?(Google::Compute::Image)}).to be_truthy
end
it '#create should create a new image' do
storage = 'https://www.googleapis.com/storage/projects/mock-project/bucket/object'
Expand Down
2 changes: 1 addition & 1 deletion spec/google/compute/machine_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@
and_return(mock_response(Google::Compute::MachineType, true))
mts = client.machine_types.list
mts.should_not be_empty
mts.all?{|mt| mt.is_a?(Google::Compute::MachineType)}.should be_true
expect(mts.all?{|mt| mt.is_a?(Google::Compute::MachineType)}).to be_truthy
end
end
2 changes: 1 addition & 1 deletion spec/google/compute/network_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
and_return(mock_response(Google::Compute::Network, true))
networks = client.networks.list
networks.should_not be_empty
networks.all?{|n| n.is_a?(Google::Compute::Network)}.should be_true
expect(networks.all?{|n| n.is_a?(Google::Compute::Network)}).to be_truthy
end

it '#create should create a new network' do
Expand Down
2 changes: 1 addition & 1 deletion spec/google/compute/region_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
and_return(mock_response(Google::Compute::Region, true))
regions = client.regions.list
regions.should_not be_empty
regions.all?{|region| region.is_a?(Google::Compute::Region)}.should be_true
expect(regions.all?{|region| region.is_a?(Google::Compute::Region)}).to be_truthy
end

end
2 changes: 1 addition & 1 deletion spec/google/compute/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
and_return(mock_response(Google::Compute::Server, true))
instances = client.instances.list(:zone => 'mock-zone')
instances.should_not be_empty
instances.all?{|i| i.is_a?(Google::Compute::Server)}.should be_true
expect(instances.all?{|i| i.is_a?(Google::Compute::Server)}).to be_truthy
end

it '#create should create an server' do
Expand Down
2 changes: 1 addition & 1 deletion spec/google/compute/snapshot_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
and_return(mock_response(Google::Compute::Snapshot, true))
snapshots = client.snapshots.list
snapshots.should_not be_empty
snapshots.all?{|s| s.is_a?(Google::Compute::Snapshot)}.should be_true
expect(snapshots.all?{|s| s.is_a?(Google::Compute::Snapshot)}).to be_truthy
end

it '#delete should delete an existing snapshot' do
Expand Down
2 changes: 1 addition & 1 deletion spec/google/compute/zone_operation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

operations = client.zoneOperations.list
operations.should_not be_empty
operations.all?{|o| o.is_a?(Google::Compute::ZoneOperation)}.should be_true
expect(operations.all?{|o| o.is_a?(Google::Compute::ZoneOperation)}).to be_truthy
end

it '#get should return an individual zone operation' do
Expand Down
2 changes: 1 addition & 1 deletion spec/google/compute/zone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
and_return(mock_response(Google::Compute::Zone, true))
zones = client.zones.list
zones.should_not be_empty
zones.all?{|zone| zone.is_a?(Google::Compute::Zone)}.should be_true
expect(zones.all?{|zone| zone.is_a?(Google::Compute::Zone)}).to be_truthy
end

end

0 comments on commit 547402b

Please sign in to comment.