|
5 | 5 | let(:branch) { 'feature-branch' }
|
6 | 6 | let(:commit) { 'abc123' }
|
7 | 7 | let(:commit_default) { Fastlane::Actions::BuildkiteUploadPipelineAction::DEFAULT_COMMIT }
|
| 8 | + let(:env_file) { 'path/to/env_file' } |
| 9 | + let(:env_file_default) { Fastlane::Actions::BuildkiteUploadPipelineAction::DEFAULT_ENV_FILE } |
8 | 10 |
|
9 | 11 | before do
|
10 | 12 | allow(File).to receive(:exist?).with(anything)
|
|
46 | 48 | { 'BUILDKITE_BRANCH' => branch, 'BUILDKITE_COMMIT' => commit_default },
|
47 | 49 | 'buildkite-agent', 'pipeline', 'upload', pipeline_file
|
48 | 50 | )
|
49 |
| - expect(Fastlane::UI).to receive(:message).with("Uploading pipeline on #{pipeline_file}, branch #{branch}, commit #{commit_default}") |
| 51 | + expect_upload_pipeline_message |
50 | 52 |
|
51 | 53 | run_described_fastlane_action(
|
52 | 54 | pipeline_file: pipeline_file,
|
|
60 | 62 | { 'BUILDKITE_COMMIT' => commit },
|
61 | 63 | 'buildkite-agent', 'pipeline', 'upload', pipeline_file
|
62 | 64 | )
|
63 |
| - expect(Fastlane::UI).to receive(:message).with("Uploading pipeline on #{pipeline_file}, commit #{commit}") |
| 65 | + expect_upload_pipeline_message(expected_branch: nil, expected_commit: commit) |
64 | 66 |
|
65 | 67 | run_described_fastlane_action(
|
66 | 68 | pipeline_file: pipeline_file,
|
|
91 | 93 | { 'BUILDKITE_BRANCH' => branch, 'BUILDKITE_COMMIT' => commit_default },
|
92 | 94 | 'buildkite-agent', 'pipeline', 'upload', pipeline_file
|
93 | 95 | )
|
94 |
| - expect(Fastlane::UI).to receive(:message).with("Uploading pipeline on #{pipeline_file}, branch #{branch}, commit #{commit_default}") |
| 96 | + expect_upload_pipeline_message |
95 | 97 |
|
96 | 98 | run_described_fastlane_action(
|
97 | 99 | pipeline_file: pipeline_file,
|
|
100 | 102 | end
|
101 | 103 |
|
102 | 104 | it 'calls the right command to upload the pipeline with env_file' do
|
103 |
| - env_file = 'path/to/env_file' |
104 | 105 | allow(File).to receive(:exist?).with(env_file).and_return(true)
|
105 | 106 | expect(Fastlane::Action).to receive(:sh).with(
|
106 | 107 | { 'BUILDKITE_BRANCH' => branch, 'BUILDKITE_COMMIT' => commit_default },
|
107 | 108 | "source #{env_file.shellescape} && buildkite-agent pipeline upload #{pipeline_file.shellescape}"
|
108 | 109 | )
|
109 |
| - expect(Fastlane::UI).to receive(:message).with("Uploading pipeline on #{pipeline_file}, branch #{branch}, commit #{commit_default}") |
110 |
| - expect(Fastlane::UI).to receive(:message).with(" - Sourcing environment file beforehand: #{env_file}") |
| 110 | + expect_upload_pipeline_message |
| 111 | + expect(Fastlane::UI).to receive(:message).with(/Sourcing environment file beforehand: #{env_file}/) |
111 | 112 |
|
112 | 113 | run_described_fastlane_action(
|
113 | 114 | pipeline_file: pipeline_file,
|
|
117 | 118 | end
|
118 | 119 |
|
119 | 120 | it 'skips sourcing env_file when it does not exist' do
|
120 |
| - env_file = 'path/to/non_existent_env_file' |
121 |
| - allow(File).to receive(:exist?).with(env_file).and_return(false) |
| 121 | + non_existent_env_file = 'path/to/non_existent_env_file' |
| 122 | + allow(File).to receive(:exist?).with(non_existent_env_file).and_return(false) |
122 | 123 | expect(Fastlane::Action).to receive(:sh).with(
|
123 | 124 | { 'BUILDKITE_BRANCH' => branch, 'BUILDKITE_COMMIT' => commit_default },
|
124 | 125 | 'buildkite-agent', 'pipeline', 'upload', pipeline_file
|
|
127 | 128 |
|
128 | 129 | run_described_fastlane_action(
|
129 | 130 | pipeline_file: pipeline_file,
|
130 |
| - env_file: env_file, |
| 131 | + env_file: non_existent_env_file, |
| 132 | + branch: branch |
| 133 | + ) |
| 134 | + end |
| 135 | + |
| 136 | + it 'uses a default env_file when no env_file is provided' do |
| 137 | + allow(File).to receive(:exist?).with(env_file_default).and_return(true) |
| 138 | + expect(Fastlane::Action).to receive(:sh).with( |
| 139 | + { 'BUILDKITE_BRANCH' => branch, 'BUILDKITE_COMMIT' => commit_default }, |
| 140 | + "source #{env_file_default} && buildkite-agent pipeline upload #{pipeline_file.shellescape}" |
| 141 | + ) |
| 142 | + expect_upload_pipeline_message |
| 143 | + expect(Fastlane::UI).to receive(:message).with(/Sourcing environment file beforehand: #{env_file_default}/) |
| 144 | + |
| 145 | + run_described_fastlane_action( |
| 146 | + pipeline_file: pipeline_file, |
131 | 147 | branch: branch
|
132 | 148 | )
|
133 | 149 | end
|
|
146 | 162 | end.to raise_error(StandardError, 'Upload failed')
|
147 | 163 | end
|
148 | 164 | end
|
| 165 | + |
| 166 | + def expect_upload_pipeline_message(expected_branch: branch, expected_commit: commit_default) |
| 167 | + expect(Fastlane::UI).to receive(:message).with( |
| 168 | + "Uploading pipeline on #{pipeline_file}#{expected_branch ? ", branch #{expected_branch}" : ''}, commit #{expected_commit}" |
| 169 | + ) |
| 170 | + end |
149 | 171 | end
|
0 commit comments