k1LoW / awspec

RSpec tests for your AWS resources.
MIT License
1.17k stars 192 forks source link

Account resource type accountID test failed. #405

Closed htnosm closed 6 years ago

htnosm commented 6 years ago

Hi,

I failed to execute "its(:account)" of Account resource type.

require 'spec_helper'

describe account do
  # failed
  its(:account) { should eq '123456789012' }
  # success
  its(:id) { should eq '123456789012' }
end
account ''
  account
    should eq "123456789012" (FAILED - 1)
  id
    should eq "123456789012"

Failures:

  1) account '' account should eq "123456789012"
     Failure/Error: its(:account) { should eq '123456789012' }

       expected: "123456789012"
            got: nil

       (compared using ==)
     # ./spec/account_test_spec.rb:5:in `block (2 levels) in <top (required)>'

Finished in 1.09 seconds (files took 8.04 seconds to load)
2 examples, 1 failure

get_caller_identity returns 'account', however, It seems that it is replaced with 'id'. Is there any reason? If is this a specification, I think that it is better to modify the document.

It was solved by replacing the following with 'account'.

+++ ./lib/awspec/type/account.rb
@@ -17,8 +17,8 @@
       @resource_via_client ||= attributes.to_struct
     end

-    def id
-      @id ||= sts_client.get_caller_identity.account
+    def account
+      @account ||= sts_client.get_caller_identity.account
     end

     def lambda

Regards.

k1LoW commented 6 years ago

Hi @htnosm

awspec resource types must have id attribute, because https://github.com/k1LoW/awspec/blob/0c39ec264004fa705c21a8df52b0b5a737dedbaf/lib/awspec/type/resource_base.rb#L10-L12 . ( account resource is special. but )

its(:account) { should eq '123456789012' } failed is bug. I'll fix it