Skip to content

Commit

Permalink
lib(directory_initializer): don't override existing shared/secrets.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
o-orand committed Dec 7, 2017
1 parent 070bdd8 commit eb49df9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
5 changes: 2 additions & 3 deletions lib/directory_initializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ def generate_default_deployment_dependencies(deployment_name)
def generate_empty_map_yaml(filename)
empty_map = {}

File.new(filename, 'w') do
|file| file << YAML.dump(empty_map)
end
puts "Skipping #{filename} generation: file already exists" if File.exist? filename
File.new(filename, 'w') { |file| file << YAML.dump(empty_map) } unless File.exist? filename

end

Expand Down
33 changes: 20 additions & 13 deletions spec/lib/directory_initializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

let(:root_deployment_name) { nil }
let(:secrets_dir) { Dir.mktmpdir('secrets-') }
let(:template_dir) { Dir.mktmpdir( 'templates-' ) }
let(:template_dir) { Dir.mktmpdir('templates-') }



Expand All @@ -31,15 +31,23 @@

context 'when shared_dir structure is valid' do
it 'creates a shared dir' do
expect( Dir).to exist("#{secrets_dir}/shared")
expect(Dir).to exist("#{secrets_dir}/shared")
end

it 'contains a secrets.yml' do
expect( File).to exist("#{secrets_dir}/shared/secrets.yml")
expect(File).to exist("#{secrets_dir}/shared/secrets.yml")
end

it 'contains a meta.yml' do
expect( File).to exist("#{secrets_dir}/shared/meta.yml")
expect(File).to exist("#{secrets_dir}/shared/meta.yml")
end

it 'shared/secrets.yml is valid' do

shared_secrets = YAML.load_file("#{secrets_dir}/shared/secrets.yml")
# YAML.load_file returns false if file is empty.

expect(shared_secrets).to be_falsey
end

end
Expand All @@ -57,19 +65,18 @@
end

context 'when files are generated with default value' do
it 'ci-deployment-overview.yml is valid' do
subject.setup_secrets!

generated_ci_overview = YAML.load_file("#{secrets_dir}/#{root_deployment_name}/ci-deployment-overview.yml")
it 'ci-deployment-overview.yml is valid' do
subject.setup_secrets!

b = binding
b.local_variable_set(:depls, 'dummy-depls')
reference = YAML.load(ERB.new(File.read("#{File.dirname __FILE__}/fixtures/ci-deployment-overview.yml.erb"), 0, '<>').result(b))
generated_ci_overview = YAML.load_file("#{secrets_dir}/#{root_deployment_name}/ci-deployment-overview.yml")

b = binding
b.local_variable_set(:depls, 'dummy-depls')
reference = YAML.load(ERB.new(File.read("#{File.dirname __FILE__}/fixtures/ci-deployment-overview.yml.erb"), 0, '<>').result(b))

expect(generated_ci_overview).to eq(reference)#, "#{secrets_dir}/#{root_deployment_name}/ci-deployment-overview.yml"
end

expect(generated_ci_overview).to eq(reference)#, "#{secrets_dir}/#{root_deployment_name}/ci-deployment-overview.yml"
end
end
end

Expand Down

0 comments on commit eb49df9

Please sign in to comment.