Skip to content

Commit

Permalink
Add support for cadetship environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
ArturT committed Aug 24, 2017
1 parent fd1a55a commit e3f6bd6
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/knapsack_pro.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
require_relative 'knapsack_pro/config/ci/buildkite'
require_relative 'knapsack_pro/config/ci/travis'
require_relative 'knapsack_pro/config/ci/snap_ci'
require_relative 'knapsack_pro/config/ci/codeship'
require_relative 'knapsack_pro/config/env'
require_relative 'knapsack_pro/config/env_generator'
require_relative 'knapsack_pro/client/api/action'
Expand Down
31 changes: 31 additions & 0 deletions lib/knapsack_pro/config/ci/codeship.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module KnapsackPro
module Config
module CI
class Codeship < Base
def node_total
# not provided
end

def node_index
# not provided
end

def node_build_id
ENV['CI_BUILD_NUMBER']
end

def commit_hash
ENV['CI_COMMIT_ID']
end

def branch
ENV['CI_BRANCH']
end

def project_dir
# not provided
end
end
end
end
end
66 changes: 66 additions & 0 deletions spec/knapsack_pro/config/ci/codeship_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
describe KnapsackPro::Config::CI::Codeship do
let(:env) { {} }

before do
stub_const('ENV', env)
end

it { should be_kind_of KnapsackPro::Config::CI::Base }

describe '#node_total' do
subject { described_class.new.node_total }

it { should be nil }
end

describe '#node_index' do
subject { described_class.new.node_index }

it { should be nil }
end

describe '#node_build_id' do
subject { described_class.new.node_build_id }

context 'when environment exists' do
let(:env) { { 'CI_BUILD_NUMBER' => 2013 } }
it { should eql 2013 }
end

context "when environment doesn't exist" do
it { should be nil }
end
end

describe '#commit_hash' do
subject { described_class.new.commit_hash }

context 'when environment exists' do
let(:env) { { 'CI_COMMIT_ID' => 'a22aec3ee5d334fd658da35646b42bc5' } }
it { should eql 'a22aec3ee5d334fd658da35646b42bc5' }
end

context "when environment doesn't exist" do
it { should be nil }
end
end

describe '#branch' do
subject { described_class.new.branch }

context 'when environment exists' do
let(:env) { { 'CI_BRANCH' => 'master' } }
it { should eql 'master' }
end

context "when environment doesn't exist" do
it { should be nil }
end
end

describe '#project_dir' do
subject { described_class.new.project_dir }

it { should be nil }
end
end

0 comments on commit e3f6bd6

Please sign in to comment.