test/test_Cloud_volumes.rb in nifty-cloud-sdk-1.7 vs test/test_Cloud_volumes.rb in nifty-cloud-sdk-1.8.beta1
- old
+ new
@@ -1,5 +1,6 @@
+# coding:utf-8
#--
# ニフティクラウドSDK for Ruby
#
# Ruby Gem Name:: nifty-cloud-sdk
# Author:: NIFTY Corporation
@@ -23,20 +24,23 @@
@valid_create_type = [
'1', '2', '3', '4', '5', '6',
1, 2, 3, 4, 5, 6
]
@basic_create_volume_options = {:size => 1, :instance_id => 'server01'}
+ @accounting_type = ['1', '2']
@describe_volumes_response_body = <<-RESPONSE
<DescribeVolumesResponse xmlns="http://xxxx.nifty.com/xxx/xxx/">
<volumeSet>
<item>
<volumeId>vol-4282672b</volumeId>
<size>800</size>
<diskType>Disk40</diskType>
<snapshotId/>
<availabilityZone>ap-japan-1a</availabilityZone>
+ <accountingType>1</accountingType>
+ <nextMonthAccountingType>1</nextMonthAccountingType>
<status>in-use</status>
<createTime>2008-05-07T11:51:50.000Z</createTime>
<attachmentSet>
<item>
<volumeId>vol-4282672b</volumeId>
@@ -57,10 +61,11 @@
<size>800</size>
<snapshotId/>
<availabilityZone>ap-japan-1a</availabilityZone>
<status>creating</status>
<createTime>2008-05-07T11:51:50.000Z</createTime>
+ <accountingType>1</accountingType>
</CreateVolumeResponse>
RESPONSE
@delete_volume_response_body = <<-RESPONSE
<DeleteVolumeResponse xmlns="http://xxxx.nifty.com/xxx/xxx/">
@@ -85,10 +90,17 @@
<device>/dev/sdh</device>
<status>detaching</status>
<attachTime>2008-05-08T11:51:50.000Z</attachTime>
</DetachVolumeResponse>
RESPONSE
+
+ @modify_volume_attribute_response_body = <<-RESPONSE
+ <ModifyVolumeAttributeResponse xmlns="http://xxxx.nifty.com/xxx/xxx/">
+ <requestId></requestId>
+ <return>true</return>
+ </ModifyVolumeAttributeResponse>
+ RESPONSE
end
# describe_volumes
specify "describe_volumes - レスポンスを正しく解析できるか" do
@api.stubs(:exec_request).returns stub(:body => @describe_volumes_response_body, :is_a? => true)
@@ -140,14 +152,15 @@
"Size" => "1",
"SnapshotId" => "a",
"AvailabilityZone" => "a",
"VolumeId" => "a",
"DiskType" => "1",
- "InstanceId" => "a"
+ "InstanceId" => "a",
+ "AccountingType" => "1"
).returns stub(:body => @create_volume_response_body, :is_a? => true)
@api.stubs(:exec_request).returns stub(:body => @create_volume_response_body, :is_a? => true)
- response = @api.create_volume(:instance_id => "a", :size => 1, :snapshot_id => "a", :availability_zone => "a", :volume_id => "a", :disk_type => 1 )
+ response = @api.create_volume(:instance_id => "a", :size => 1, :snapshot_id => "a", :availability_zone => "a", :volume_id => "a", :disk_type => 1, :accounting_type => 1)
end
specify "create_volume - :size, instance_id正常" do
@api.stubs(:exec_request).returns stub(:body => @create_volume_response_body, :is_a? => true)
@valid_create_size.each do |size|
@@ -177,10 +190,17 @@
@api.stubs(:exec_request).returns stub(:body => @create_volume_response_body, :is_a? => true)
@valid_create_type.each do |type|
lambda { @api.create_volume(@basic_create_volume_options.merge(:disk_type => type)) }.should.not.raise(NIFTY::ArgumentError)
end
end
+
+ specify "create_volume - :disk_type正常" do
+ @api.stubs(:exec_request).returns stub(:body => @create_volume_response_body, :is_a? => true)
+ @accounting_type.each do |type|
+ lambda { @api.create_volume(@basic_create_volume_options.merge(:accounting_type => type)) }.should.not.raise(NIFTY::ArgumentError)
+ end
+ end
specify "create_volume - :size未指定" do
lambda { @api.create_volume }.should.raise(NIFTY::ArgumentError)
lambda { @api.create_volume(:size => nil) }.should.raise(NIFTY::ArgumentError)
lambda { @api.create_volume(:size => '') }.should.raise(NIFTY::ArgumentError)
@@ -195,11 +215,16 @@
lambda { @api.create_volume(:size => 1) }.should.raise(NIFTY::ArgumentError)
lambda { @api.create_volume(:size => 1, :key_name => nil) }.should.raise(NIFTY::ArgumentError)
lambda { @api.create_volume(:size => 1, :key_name => '') }.should.raise(NIFTY::ArgumentError)
end
+ specify "create_volume - :accounting_type不正" do
+ lambda { @api.create_volume(@basic_create_volume_options.merge(:accounting_type => 'type')) }.should.raise(NIFTY::ArgumentError)
+ lambda { @api.create_volume(@basic_create_volume_options.merge(:accounting_type => 3)) }.should.raise(NIFTY::ArgumentError)
+ end
+
# delete_volume
specify "delete_volume - レスポンスを正しく解析できるか" do
@api.stubs(:exec_request).returns stub(:body => @delete_volume_response_body, :is_a? => true)
response = @api.delete_volume(:volume_id => 'vol')
response.return.should.equal 'true'
@@ -320,6 +345,63 @@
specify "detach_volume - :force異常" do
lambda { @api.detach_volume(:volume_id => 'foo', :force => 'foo') }.should.raise(NIFTY::ArgumentError)
lambda { @api.detach_volume(:volume_id => 'foo', :force => 1) }.should.raise(NIFTY::ArgumentError)
end
+ # modify_volume_attribute
+ specify "modify_volume_attribute - レスポンスを正しく解析できるか" do
+ @api.stubs(:exec_request).returns stub(:body => @modify_volume_attribute_response_body, :is_a? => true)
+ response = @api.modify_volume_attribute(:volume_id => "vol1", :attribute => 'accountingType', :value => '1')
+ response.return.should.equal "true"
+ end
+
+ specify "modify_volume_attribute - パラメータが正しく作られるか" do
+ @api.stubs(:make_request).with('Action' => 'ModifyVolumeAttribute',
+ 'VolumeId' => 'vol01',
+ 'Attribute' => 'accountingType',
+ 'Value' => '1').returns stub(:body => @modify_volume_attribute_response_body, :is_a? => true)
+ @api.stubs(:exec_request).returns stub(:body => @modify_volume_attribute_response_body, :is_a? => true)
+ response = @api.modify_volume_attribute(:volume_id => "vol01", :attribute => 'accountingType', :value => '1')
+ end
+
+ specify "modify_volume_attribute - :volume_id正常" do
+ @api.stubs(:exec_request).returns stub(:body => @modify_volume_attribute_response_body, :is_a? => true)
+ lambda { @api.modify_volume_attribute(:volume_id => 'foo', :attribute => 'accountingType', :value => '1') }.should.not.raise(NIFTY::ArgumentError)
+ lambda { @api.modify_volume_attribute(:volume_id => 12345, :attribute => 'accountingType', :value => '1') }.should.not.raise(NIFTY::ArgumentError)
+ end
+
+ specify "modify_volume_attribute - :attribute,:value正常" do
+ @api.stubs(:exec_request).returns stub(:body => @modify_volume_attribute_response_body, :is_a? => true)
+ { 'accountingType' => @accounting_type
+ }.each do |attr, arr|
+ arr.each do |val|
+ lambda { @api.modify_volume_attribute(:volume_id => "vol01", :attribute => attr, :value => val) }.should.not.raise(NIFTY::ArgumentError)
+ end
+ end
+ end
+
+ specify "modify_volume_attribute - :volume_id未指定" do
+ lambda { @api.modify_volume_attribute }.should.raise(NIFTY::ArgumentError)
+ [ nil, ''].each do |id|
+ lambda { @api.modify_volume_attribute(:volume_id => id) }.should.raise(NIFTY::ArgumentError)
+ end
+ lambda { @api.modify_volume_attribute }.should.raise(NIFTY::ArgumentError)
+ end
+
+ specify "modify_volume_attribute - :attribute未指定/不正" do
+ lambda { @api.modify_volume_attribute(:volume_id => "vol01") }.should.raise(NIFTY::ArgumentError)
+ lambda { @api.modify_volume_attribute(:volume_id => "vol01", :attribute => nil) }.should.raise(NIFTY::ArgumentError)
+ lambda { @api.modify_volume_attribute(:volume_id => "vol01", :attribute => '') }.should.raise(NIFTY::ArgumentError)
+ lambda { @api.modify_volume_attribute(:volume_id => "vol01", :attribute => 'hoge') }.should.raise(NIFTY::ArgumentError)
+ lambda { @api.modify_volume_attribute(:volume_id => "vol01", :attribute => 3) }.should.raise(NIFTY::ArgumentError)
+ end
+
+ specify "modify_volume_attribute - :value未指定/不正" do
+ attribute = %w(accountingType)
+ attribute.each do |attr|
+ lambda { @api.modify_volume_attribute(:volume_id => "i-10a64379", :attribute => attr ) }.should.raise(NIFTY::ArgumentError)
+ lambda { @api.modify_volume_attribute(:volume_id => "i-10a64379", :attribute => attr, :value => nil ) }.should.raise(NIFTY::ArgumentError)
+ lambda { @api.modify_volume_attribute(:volume_id => "i-10a64379", :attribute => attr, :value => 'hoge' ) }.should.raise(NIFTY::ArgumentError)
+ lambda { @api.modify_volume_attribute(:volume_id => "i-10a64379", :attribute => attr, :value => 3 ) }.should.raise(NIFTY::ArgumentError)
+ end
+ end
end