-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
job_test.rb
56 lines (48 loc) · 1.95 KB
/
job_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require "test_helper"
class JobTest < ActiveSupport::TestCase
context 'validations' do
should validate_presence_of(:url)
should validate_uniqueness_of(:id).case_insensitive
end
setup do
@job = Job.create(url: 'https://github.com/ecosyste-ms/digest/archive/refs/heads/main.zip', sidekiq_id: '123', ip: '123.456.78.9')
end
test 'check_status' do
Sidekiq::Status.expects(:status).with(@job.sidekiq_id).returns(:queued)
@job.check_status
assert_equal @job.status, "queued"
end
test 'parse_licenses_async' do
ParseLicensesWorker.expects(:perform_async).with(@job.id)
@job.parse_licenses_async
end
test 'parse_licenses' do
Dir.mktmpdir do |dir|
FileUtils.cp(File.join(file_fixture_path, 'main.zip'), dir)
results = @job.parse_licenses(dir)
assert_equal results[:licenses].length, 1
assert_equal results[:matched_files].length, 1
assert_equal results[:licenses].first[:name], "GNU Affero General Public License v3.0"
assert_equal results[:matched_files].first[:filename], "LICENSE"
end
end
test 'download_file' do
stub_request(:get, "https://github.com/ecosyste-ms/digest/archive/refs/heads/main.zip")
.to_return({ status: 200, body: file_fixture('main.zip') })
Dir.mktmpdir do |dir|
sha256 = @job.download_file(dir)
assert_equal sha256, '546b13eb945186f67d2480910dce773ca0e2539b80cadafe7bb2fe3c537800ec'
end
end
test 'works with jar files' do
@job = Job.create(url: 'https://repo.clojars.org/org/clojars/majorcluster/clj-data-adapter/0.2.1/clj-data-adapter-0.2.1.jar', sidekiq_id: '123', ip: '123.456.78.9')
Dir.mktmpdir do |dir|
FileUtils.cp(File.join(file_fixture_path, 'clj-data-adapter-0.2.1.jar'), dir)
results = @job.parse_licenses(dir)
assert_equal results[:licenses].length, 0
assert_equal results[:matched_files].length, 0
assert_empty results[:licenses]
assert_empty results[:matched_files]
end
end
end