فهرست منبع

Use the stub_responses feature of the new aws-sdk

https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/ClientStubs.html
Akinori MUSHA 1 سال پیش
والد
کامیت
dc2156fcb7
1فایلهای تغییر یافته به همراه10 افزوده شده و 4 حذف شده
  1. 10 4
      spec/models/agents/s3_agent_spec.rb

+ 10 - 4
spec/models/agents/s3_agent_spec.rb

@@ -65,7 +65,9 @@ describe Agents::S3Agent do
 
   describe "#validating" do
     it "validates the key" do
-      expect(@checker).to receive(:client) { raise Aws::S3::Errors::SignatureDoesNotMatch.new('', '') }
+      expect(@checker).to receive(:client) {
+        Aws::S3::Client.new(stub_responses: { list_buckets: ['SignatureDoesNotMatch'] })
+      }
       expect(@checker.validate_access_key_id).to be_falsy
     end
 
@@ -139,15 +141,19 @@ describe Agents::S3Agent do
 
       context "error handling" do
         it "handles AccessDenied exceptions" do
-          expect(@checker).to receive(:get_bucket_contents) { raise Aws::S3::Errors::AccessDenied.new('', '') }
+          expect(@checker).to receive(:client) {
+            Aws::S3::Client.new(stub_responses: { list_objects: ['AccessDenied'] })
+          }
           expect { @checker.check }.to change(AgentLog, :count).by(1)
           expect(AgentLog.last.message).to match(/Could not access 'testbucket' Aws::S3::Errors::AccessDenied/)
         end
 
         it "handles generic S3 exceptions" do
-          expect(@checker).to receive(:get_bucket_contents) { raise Aws::S3::Errors::PermanentRedirect.new('', 'error') }
+          expect(@checker).to receive(:client) {
+            Aws::S3::Client.new(stub_responses: { list_objects: ['PermanentRedirect'] })
+          }
           expect { @checker.check }.to change(AgentLog, :count).by(1)
-          expect(AgentLog.last.message).to eq("Aws::S3::Errors::PermanentRedirect: error")
+          expect(AgentLog.last.message).to eq("Aws::S3::Errors::PermanentRedirect: stubbed-response-error-message")
         end
       end
     end