|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe Overcommit::Hook::PreCommit::Hadolint do |
| 4 | + let(:config) { Overcommit::ConfigurationLoader.default_configuration } |
| 5 | + let(:context) { double('context') } |
| 6 | + let(:applicable_files) { %w[Dockerfile Dockerfile.web] } |
| 7 | + subject { described_class.new(config, context) } |
| 8 | + |
| 9 | + before do |
| 10 | + subject.stub(:applicable_files).and_return(applicable_files) |
| 11 | + end |
| 12 | + |
| 13 | + around do |example| |
| 14 | + repo do |
| 15 | + example.run |
| 16 | + end |
| 17 | + end |
| 18 | + |
| 19 | + before do |
| 20 | + subject.stub(:execute).with(%w[hadolint], args: Array(applicable_files.first)). |
| 21 | + and_return(result_dockerfile) |
| 22 | + subject.stub(:execute).with(%w[hadolint], args: Array(applicable_files.last)). |
| 23 | + and_return(result_dockerfile_web) |
| 24 | + end |
| 25 | + |
| 26 | + context 'and has 2 suggestions' do |
| 27 | + let(:result_dockerfile) do |
| 28 | + double( |
| 29 | + success?: false, |
| 30 | + stdout: <<-EOF |
| 31 | +Dockerfile:5 DL3015 Avoid additional packages by specifying `--no-install-recommends` |
| 32 | + EOF |
| 33 | + ) |
| 34 | + end |
| 35 | + let(:result_dockerfile_web) do |
| 36 | + double( |
| 37 | + success?: false, |
| 38 | + stdout: <<-EOF |
| 39 | +Dockerfile.web:13 DL3020 Use COPY instead of ADD for files and folders |
| 40 | + EOF |
| 41 | + ) |
| 42 | + end |
| 43 | + |
| 44 | + it { should fail_hook } |
| 45 | + end |
| 46 | + |
| 47 | + context 'and has single suggestion for double quote' do |
| 48 | + let(:result_dockerfile) do |
| 49 | + double( |
| 50 | + success?: false, |
| 51 | + stdout: <<-EOF |
| 52 | +Dockerfile:11 SC2086 Double quote to prevent globbing and word splitting. |
| 53 | + EOF |
| 54 | + ) |
| 55 | + end |
| 56 | + let(:result_dockerfile_web) do |
| 57 | + double(success?: true, stdout: '') |
| 58 | + end |
| 59 | + |
| 60 | + it { should fail_hook } |
| 61 | + end |
| 62 | + |
| 63 | + context 'and does not have any suggestion' do |
| 64 | + let(:result_dockerfile) do |
| 65 | + double(success?: true, stdout: '') |
| 66 | + end |
| 67 | + let(:result_dockerfile_web) do |
| 68 | + double(success?: true, stdout: '') |
| 69 | + end |
| 70 | + |
| 71 | + it { should pass } |
| 72 | + end |
| 73 | +end |
0 commit comments