Skip to content
This repository has been archived by the owner on Jan 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #100 from dhollinger/tests
Browse files Browse the repository at this point in the history
Added some more tests for the workers
  • Loading branch information
bastelfreak authored May 13, 2019
2 parents d450c7b + f7d3065 commit efa075d
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
22 changes: 22 additions & 0 deletions spec/app/controllers/api/v1/r10k/environment_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,26 @@
Net::HTTP.post URI('http://localhost/api/v1/r10k/environment'), body, headers
end
end

context 'ignoring environment' do
let(:body) { File.read('spec/fixtures/github/create.json') }
let(:headers) do
{
'CONTENT_TYPE' => 'application/json',
'HTTP_X_GITHUB_EVENT' => 'Push Event',
'ACCEPT' => '*/*',
'ACCEPT_ENCODING' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'USER_AGENT' => 'Ruby'
}
end

before do
APP_CONFIG['ignore_environments'] = 'master'
end

it 'returns 200 and skips deployment' do
stub_request(:post, 'localhost/api/v1/r10k/environment')
.with(body: body, headers: headers).to_return(status: 200)
end
end
end
27 changes: 27 additions & 0 deletions spec/app/workers/deploy/environment_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'spec_helper'

describe Deploy::EnvironmentWorker do
let(:environment) { 'test' }
let(:config) do
{
sources: {
main: {
remote: 'https://example.com/foo/bar',
basedir: '/etc/foo/bar'
}
}
}
end

let(:deploy) { double('R10K::Action::Deploy::Environment') }

before do
allow(R10K::Action::Deploy::Environment).to receive(:new) { deploy }
end

it 'successfully deploys environment' do
job = Deploy::EnvironmentWorker.new
expect(deploy).to receive(:call) { true }
job.perform(environment, config)
end
end
27 changes: 27 additions & 0 deletions spec/app/workers/deploy/module_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'spec_helper'

describe Deploy::ModuleWorker do
let(:ppt_module) { 'foobar' }
let(:config) do
{
sources: {
main: {
remote: 'https://example.com/foo/bar',
basedir: '/etc/foo/bar'
}
}
}
end

let(:deploy) { double('R10K::Action::Deploy::Module') }

before do
allow(R10K::Action::Deploy::Module).to receive(:new) { deploy }
end

it 'successfully deploys a module' do
job = Deploy::ModuleWorker.new
expect(deploy).to receive(:call) { true }
job.perform(ppt_module, config)
end
end
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require 'simplecov'
require 'simplecov-console'
require 'sidekiq/testing'

SimpleCov.formatters = [
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::Console
Expand All @@ -12,6 +14,8 @@
add_filter '.vendor'
end

Sidekiq::Logging.logger = nil

ENV['SINATRA_ENV'] = 'test'

require_relative '../config/environment'
Expand Down

0 comments on commit efa075d

Please sign in to comment.