Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.

Allow for overriding pipelines and private variable settings in the constructor arguments #1

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/concourse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,15 @@ def self.rc_rubies

def initialize project_name, args={}
@project_name = project_name

@pipeline_erb_filename = args[:pipeline_erb_filename] || "#{project_name}.yml"
@pipeline_filename = args[:pipeline_filename] || @pipeline_erb_filename.sub(/.yml$/, '.final.yml')
@private_var_file = args[:private_var_file] || 'private.yml'

@directory = args[:directory] || DEFAULT_DIRECTORY
@pipeline_filename = File.join(@directory, "#{project_name}.final.yml")
@pipeline_erb_filename = File.join(@directory, "#{project_name}.yml")
@private_var_file = File.join(@directory, "private.yml")
@pipeline_erb_filename = File.join(@directory, @pipeline_erb_filename)
@pipeline_filename = File.join(@directory, @pipeline_filename)
@private_var_file = File.join(@directory, @private_var_file)
end

def erbify document_string, *args
Expand Down
34 changes: 34 additions & 0 deletions spec/concourse/rake_task_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "spec_helper"
require 'securerandom'

RSpec.describe Concourse do
describe ".new" do
Expand All @@ -24,6 +25,39 @@
expect(Concourse.new("myproject", directory: "ci").directory).to eq "ci"
end
end

describe '#pipeline_filename' do
subject { instance.pipeline_filename }

let(:instance) { Concourse.new(project_name, args) }
let(:project_name) { 'myproject' }

context 'when no pipeline_filename is specified' do
let(:args) { {} }

it "defaults to use project_name" do
expect(subject).to eq "#{instance.directory}/#{project_name}.final.yml"
end
end

context 'when pipeline_filename is specified' do
let(:args) { {pipeline_filename: pipeline_filename} }
let(:pipeline_filename) { SecureRandom.hex(12) }

it 'uses the specified pipeline_filename' do
expect(subject).to eq "#{instance.directory}/#{pipeline_filename}"
end
end

context 'when pipeline_erb_filename is specified' do
let(:args) { {pipeline_erb_filename: "#{pipeline_erb_filename}.yml"} }
let(:pipeline_erb_filename) { SecureRandom.hex(12) }

it 'derives the pipeline_filename from the pipeline_erb_filename' do
expect(subject).to eq "#{instance.directory}/#{pipeline_erb_filename}.final.yml"
end
end
end
end

def in_tmp_dir &block
Expand Down