Skip to content

Commit 2665c7b

Browse files
committed
Update tests to consider the default env_file
1 parent 2478ff8 commit 2665c7b

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

spec/buildkite_upload_pipeline_action_spec.rb

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
let(:branch) { 'feature-branch' }
66
let(:commit) { 'abc123' }
77
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 }
810

911
before do
1012
allow(File).to receive(:exist?).with(anything)
@@ -46,7 +48,7 @@
4648
{ 'BUILDKITE_BRANCH' => branch, 'BUILDKITE_COMMIT' => commit_default },
4749
'buildkite-agent', 'pipeline', 'upload', pipeline_file
4850
)
49-
expect(Fastlane::UI).to receive(:message).with("Uploading pipeline on #{pipeline_file}, branch #{branch}, commit #{commit_default}")
51+
expect_upload_pipeline_message
5052

5153
run_described_fastlane_action(
5254
pipeline_file: pipeline_file,
@@ -60,7 +62,7 @@
6062
{ 'BUILDKITE_COMMIT' => commit },
6163
'buildkite-agent', 'pipeline', 'upload', pipeline_file
6264
)
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)
6466

6567
run_described_fastlane_action(
6668
pipeline_file: pipeline_file,
@@ -91,7 +93,7 @@
9193
{ 'BUILDKITE_BRANCH' => branch, 'BUILDKITE_COMMIT' => commit_default },
9294
'buildkite-agent', 'pipeline', 'upload', pipeline_file
9395
)
94-
expect(Fastlane::UI).to receive(:message).with("Uploading pipeline on #{pipeline_file}, branch #{branch}, commit #{commit_default}")
96+
expect_upload_pipeline_message
9597

9698
run_described_fastlane_action(
9799
pipeline_file: pipeline_file,
@@ -100,14 +102,13 @@
100102
end
101103

102104
it 'calls the right command to upload the pipeline with env_file' do
103-
env_file = 'path/to/env_file'
104105
allow(File).to receive(:exist?).with(env_file).and_return(true)
105106
expect(Fastlane::Action).to receive(:sh).with(
106107
{ 'BUILDKITE_BRANCH' => branch, 'BUILDKITE_COMMIT' => commit_default },
107108
"source #{env_file.shellescape} && buildkite-agent pipeline upload #{pipeline_file.shellescape}"
108109
)
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}/)
111112

112113
run_described_fastlane_action(
113114
pipeline_file: pipeline_file,
@@ -117,8 +118,8 @@
117118
end
118119

119120
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)
122123
expect(Fastlane::Action).to receive(:sh).with(
123124
{ 'BUILDKITE_BRANCH' => branch, 'BUILDKITE_COMMIT' => commit_default },
124125
'buildkite-agent', 'pipeline', 'upload', pipeline_file
@@ -127,7 +128,22 @@
127128

128129
run_described_fastlane_action(
129130
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,
131147
branch: branch
132148
)
133149
end
@@ -146,4 +162,10 @@
146162
end.to raise_error(StandardError, 'Upload failed')
147163
end
148164
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
149171
end

0 commit comments

Comments
 (0)