Skip to content

Commit

Permalink
Merge pull request #2797 from sonalkr132/coverage
Browse files Browse the repository at this point in the history
Add test for downloads controller and sqs worker
  • Loading branch information
sonalkr132 authored Sep 16, 2021
2 parents 1890384 + 44adccc commit 454d333
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/functional/api/v1/versions/downloads_controller_test.rb
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
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "simplecov"
SimpleCov.start "rails" do
add_filter "lib/tasks"
add_filter "lib/lograge"
end

ENV["RAILS_ENV"] ||= "test"
Expand Down
78 changes: 78 additions & 0 deletions test/unit/sqs_worker_test.rb
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

0 comments on commit 454d333

Please sign in to comment.