Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit d20c89e

Browse files
committed
Mock out the tests
1 parent b3f0718 commit d20c89e

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

lib/codecov.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def upload_to_v4(url, report, query, query_without_token)
352352
https.use_ssl = !url.match(/^https/).nil?
353353

354354
puts ['-> '.green, 'Pinging Codecov'].join(' ')
355-
puts "#{url}/#{uri.path}?#{query_without_token}"
355+
puts "#{url}#{uri.path}?#{query_without_token}"
356356

357357
req = Net::HTTP::Post.new(
358358
"#{uri.path}?#{query}",

test/helper.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@
1111
SimpleCov.formatter = SimpleCov::Formatter::Codecov if ENV['CI'] == 'true'
1212

1313
require 'minitest/autorun'
14-
require 'mocha/setup'
15-
14+
require 'mocha/minitest'
1615
require 'webmock/minitest'

test/test_codecov.rb

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,31 @@ def upload(success=true)
3939
stub_file('/path/lib/somefile.rb', [1, nil, 1, 1, 1, 0, 0, nil, 1, nil])
4040
])
4141
SimpleCov.stubs(:root).returns('/path')
42-
data = formatter.format(result)
42+
success_stubs if success
43+
data = formatter.format(result, false)
4344
puts data
4445
puts data['params']
4546
if success
4647
assert_successful_upload(data)
4748
end
49+
WebMock.reset!
4850
data
4951
end
5052

53+
def success_stubs
54+
stub_request(:post, %r{https:\/\/codecov.io\/upload})
55+
.to_return(
56+
status: 200,
57+
body: "https://codecov.io/gh/fake\n" \
58+
'https://storage.googleapis.com/codecov/fake'
59+
)
60+
stub_request(:put, %r{https:\/\/storage.googleapis.com\/})
61+
.to_return(
62+
status: 200,
63+
body: ''
64+
)
65+
end
66+
5167
def assert_successful_upload(data)
5268
assert_equal(data['result']['uploaded'], true)
5369
assert_equal(data['result']['message'], 'Coverage reports upload successfully')
@@ -521,6 +537,13 @@ def test_filenames_are_shortened_correctly
521537
end
522538

523539
def test_invalid_token
540+
stub_request(:post, %r{https:\/\/codecov.io\/upload})
541+
.to_return(
542+
status: 400,
543+
body: "HTTP 400\n" \
544+
'Provided token is not a UUID.'
545+
)
546+
524547
ENV['CODECOV_TOKEN'] = 'fake'
525548
result = upload(false)
526549
assert_equal(false, result['result']['uploaded'])

0 commit comments

Comments
 (0)