|
139 | 139 | end |
140 | 140 |
|
141 | 141 | describe 'cd4pe_job_helper::initialize' do |
142 | | - it 'Passes the docker run args through without modifying the structure.' do |
| 142 | + it 'Passes the container run args through without modifying the structure.' do |
143 | 143 | arg1 = '--testarg=woot' |
144 | 144 | arg2 = '--otherarg=hello' |
145 | 145 | arg3 = '--whatever=isclever' |
146 | | - user_specified_docker_run_args = [arg1, arg2, arg3] |
| 146 | + user_specified_container_run_args = [arg1, arg2, arg3] |
147 | 147 |
|
148 | | - job_helper = CD4PEJobRunner.new(windows_job: @windows_job, working_dir: @working_dir, docker_run_args: user_specified_docker_run_args, job_token: @job_token, web_ui_endpoint: @web_ui_endpoint, job_owner: @job_owner, job_instance_id: @job_instance_id, logger: @logger, secrets: @secrets) |
| 148 | + job_helper = CD4PEJobRunner.new(windows_job: @windows_job, working_dir: @working_dir, container_run_args: user_specified_container_run_args, job_token: @job_token, web_ui_endpoint: @web_ui_endpoint, job_owner: @job_owner, job_instance_id: @job_instance_id, logger: @logger, secrets: @secrets) |
149 | 149 |
|
150 | | - expect(job_helper.docker_run_args).to eq("#{arg1} #{arg2} #{arg3}") |
| 150 | + expect(job_helper.container_run_args).to eq("#{arg1} #{arg2} #{arg3}") |
151 | 151 | end |
152 | 152 |
|
153 | 153 | it 'Sets the HOME and REPO_DIR env vars' do |
|
157 | 157 | expect(ENV['REPO_DIR']).to eq("#{@working_dir}/cd4pe_job/repo") |
158 | 158 | end |
159 | 159 | end |
160 | | - |
161 | | - describe 'cd4pe_job_helper::update_docker_image' do |
162 | | - let(:test_docker_image) { 'puppetlabs/test:10.0.1' } |
163 | | - it 'Generates a docker pull command.' do |
164 | | - job_helper = CD4PEJobRunner.new(windows_job: @windows_job, working_dir: @working_dir, docker_image: test_docker_image, job_token: @job_token, web_ui_endpoint: @web_ui_endpoint, job_owner: @job_owner, job_instance_id: @job_instance_id, logger: @logger, secrets: @secrets) |
165 | | - docker_pull_command = job_helper.get_docker_pull_cmd |
166 | | - expect(docker_pull_command).to eq("docker pull #{test_docker_image}") |
167 | | - end |
168 | | - |
169 | | - context 'with config' do |
170 | | - let(:hostname) { 'host1' } |
171 | | - let(:creds_json) { {auths: {hostname => {}}}.to_json } |
172 | | - let(:creds_b64) { Base64.encode64(creds_json) } |
173 | | - let(:cert_txt) { 'junk' } |
174 | | - let(:cert_b64) { Base64.encode64(cert_txt) } |
175 | | - |
176 | | - it 'Uses config when present.' do |
177 | | - job_helper = CD4PEJobRunner.new(windows_job: @windows_job, working_dir: @working_dir, docker_image: test_docker_image, docker_pull_creds: creds_b64, job_token: @job_token, web_ui_endpoint: @web_ui_endpoint, job_owner: @job_owner, job_instance_id: @job_instance_id, logger: @logger, secrets: @secrets) |
178 | | - config_json = File.join(@working_dir, '.docker', 'config.json') |
179 | | - expect(File.exist?(config_json)).to be(true) |
180 | | - expect(File.read(config_json)).to eq(creds_json) |
181 | | - |
182 | | - docker_pull_command = job_helper.get_docker_pull_cmd |
183 | | - expect(docker_pull_command).to eq("docker --config #{File.join(@working_dir, '.docker')} pull #{test_docker_image}") |
184 | | - end |
185 | | - |
186 | | - it 'Registers the CA cert when provided.' do |
187 | | - job_helper = CD4PEJobRunner.new(windows_job: @windows_job, working_dir: @working_dir, docker_image: test_docker_image, docker_pull_creds: creds_b64, base_64_ca_cert: cert_b64, job_token: @job_token, web_ui_endpoint: @web_ui_endpoint, job_owner: @job_owner, job_instance_id: @job_instance_id, logger: @logger, secrets: @secrets) |
188 | | - |
189 | | - cert_file = File.join(@certs_dir, hostname, 'ca.crt') |
190 | | - expect(File.exist?(cert_file)).to be(true) |
191 | | - expect(File.read(cert_file)).to eq(cert_txt) |
192 | | - end |
193 | | - end |
194 | | - end |
195 | | - |
196 | | - describe 'cd4pe_job_helper::get_docker_run_cmd' do |
197 | | - it 'Generates the correct docker run command.' do |
198 | | - test_manifest_type = "AFTER_JOB_SUCCESS" |
199 | | - test_docker_image = 'puppetlabs/test:10.0.1' |
200 | | - arg1 = '--testarg=woot' |
201 | | - arg2 = '--otherarg=hello' |
202 | | - arg3 = '--whatever=doesntmatter' |
203 | | - user_specified_docker_run_args = [arg1, arg2, arg3] |
204 | | - job_type = @windows_job ? 'windows' : 'unix' |
205 | | - |
206 | | - job_helper = CD4PEJobRunner.new(windows_job: @windows_job, working_dir: @working_dir, docker_image: test_docker_image, docker_run_args: user_specified_docker_run_args, job_token: @job_token, web_ui_endpoint: @web_ui_endpoint, job_owner: @job_owner, job_instance_id: @job_instance_id, logger: @logger, secrets: @secrets) |
207 | | - |
208 | | - docker_run_command = job_helper.get_docker_run_cmd(test_manifest_type) |
209 | | - cmd_parts = docker_run_command.split(' ') |
210 | | - |
211 | | - expect(cmd_parts[0]).to eq('docker') |
212 | | - expect(cmd_parts[1]).to eq('run') |
213 | | - expect(cmd_parts[2]).to eq('--rm') |
214 | | - expect(cmd_parts[3]).to eq(arg1) |
215 | | - expect(cmd_parts[4]).to eq(arg2) |
216 | | - expect(cmd_parts[5]).to eq(arg3) |
217 | | - expect(cmd_parts[6]).to eq('-e') |
218 | | - expect(cmd_parts[7]).to eq('secret1') |
219 | | - expect(cmd_parts[8]).to eq('-e') |
220 | | - expect(cmd_parts[9]).to eq('secret2') |
221 | | - expect(cmd_parts[10]).to eq('-v') |
222 | | - expect(cmd_parts[11].end_with?("/#{File.basename(@working_dir)}/cd4pe_job/repo:/repo\"")).to be(true) |
223 | | - expect(cmd_parts[12]).to eq('-v') |
224 | | - expect(cmd_parts[13].end_with?("/#{File.basename(@working_dir)}/cd4pe_job/jobs/#{job_type}:/cd4pe_job\"")).to be(true) |
225 | | - expect(cmd_parts[14]).to eq(test_docker_image) |
226 | | - expect(cmd_parts[15]).to eq('"/cd4pe_job/AFTER_JOB_SUCCESS"') |
227 | | - end |
228 | | - end |
229 | 160 | end |
230 | 161 |
|
231 | 162 | describe 'cd4pe_job_helper::run_job' do |
|
0 commit comments