-
-
Notifications
You must be signed in to change notification settings - Fork 931
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2797 from sonalkr132/coverage
Add test for downloads controller and sqs worker
- Loading branch information
Showing
3 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
test/functional/api/v1/versions/downloads_controller_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require "test_helper" | ||
|
||
class Api::V1::Versions::DownloadsControllerTest < ActionController::TestCase | ||
context "on GET to index" do | ||
setup do | ||
@rubygem = create(:rubygem, number: "0.1.0") | ||
get :index, params: { version_id: @rubygem.latest_version.number, format: "json" } | ||
end | ||
|
||
should respond_with :gone | ||
end | ||
|
||
context "on GET to search" do | ||
setup do | ||
@rubygem = create(:rubygem, number: "0.1.0") | ||
get :search, params: { version_id: @rubygem.latest_version.number, format: "json" } | ||
end | ||
|
||
should respond_with :gone | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
require "test_helper" | ||
require_relative "../../lib/shoryuken/sqs_worker" | ||
|
||
class SqsWorkerTest < ActiveSupport::TestCase | ||
setup do | ||
@sqs_worker = SqsWorker.new | ||
@body = { | ||
"Records" => [{ | ||
"eventVersion" => "2.2", | ||
"eventSource" => "aws => s3", | ||
"awsRegion" => "us-west-2", | ||
"eventTime" => "The time, in ISO-8601 format, for example, 1970-01-01T00 => 00 => 00.000Z, when Amazon S3 finished processing the request", | ||
"eventName" => "event-type", | ||
"userIdentity" => { | ||
"principalId" => "Amazon-customer-ID-of-the-user-who-caused-the-event" | ||
}, | ||
"requestParameters" => { | ||
"sourceIPAddress" => "ip-address-where-request-came-from" | ||
}, | ||
"responseElements" => { | ||
"x-amz-request-id" => "Amazon S3 generated request ID", | ||
"x-amz-id-2" => "Amazon S3 host that processed the request" | ||
}, | ||
"s3" => { | ||
"s3SchemaVersion" => "1.0", | ||
"configurationId" => "ID found in the bucket notification configuration", | ||
"bucket" => { | ||
"name" => "bucket-name", | ||
"ownerIdentity" => { | ||
"principalId" => "Amazon-customer-ID-of-the-bucket-owner" | ||
}, | ||
"arn" => "bucket-ARN" | ||
}, | ||
"object" => { | ||
"key" => "object-key", | ||
"size" => "object-size in bytes", | ||
"eTag" => "object eTag", | ||
"versionId" => "object version if bucket is versioning-enabled, otherwise null", | ||
"sequencer" => "a string representation of a hexadecimal value used to determine event sequence, only used with PUTs and DELETEs" | ||
} | ||
}, | ||
"glacierEventData" => { | ||
"restoreEventData" => { | ||
"lifecycleRestorationExpiryTime" => "The time, in ISO-8601 format, for example, 1970-01-01T00 => 00 => 00.000Z, of Restore Expiry", | ||
"lifecycleRestoreStorageClass" => "Source storage class for restore" | ||
} | ||
} | ||
}] | ||
} | ||
end | ||
|
||
context "#perform" do | ||
should "create Logticket" do | ||
StatsD.expects(:increment).with("fastly_log_processor.s3_entry_fetched") | ||
StatsD.expects(:increment).with("fastly_log_processor.enqueued") | ||
assert_difference "Delayed::Job.count", 1 do | ||
@sqs_worker.perform(nil, @body) | ||
end | ||
|
||
log_ticket = LogTicket.last | ||
assert_equal "bucket-name", log_ticket.directory | ||
assert_equal "object-key", log_ticket.key | ||
assert_equal "pending", log_ticket.status | ||
end | ||
|
||
should "not create duplicate LogTicket" do | ||
duplicate_record = @body["Records"].first | ||
@body["Records"] << duplicate_record | ||
|
||
StatsD.expects(:increment).with("fastly_log_processor.s3_entry_fetched") | ||
StatsD.expects(:increment).with("fastly_log_processor.enqueued").twice | ||
StatsD.expects(:increment).with("fastly_log_processor.duplicated") | ||
assert_difference "Delayed::Job.count", 1 do | ||
@sqs_worker.perform(nil, @body) | ||
end | ||
end | ||
end | ||
end |