blob: 4ae97f589cf2a16800f2ff3d18d8bce6b5698c6b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# frozen_string_literal: true
module QA
RSpec.describe 'Verify', :runner, product_group: :pipeline_authoring do
describe 'Pipeline with project file variables' do
let(:executor) { "qa-runner-#{Faker::Alphanumeric.alphanumeric(number: 8)}" }
let(:project) do
Resource::Project.fabricate_via_api! do |project|
project.name = 'project-with-file-variables'
end
end
let!(:runner) do
Resource::Runner.fabricate! do |runner|
runner.project = project
runner.name = executor
runner.tags = [executor]
end
end
let(:add_ci_file) do
Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = project
commit.commit_message = 'Add .gitlab-ci.yml'
commit.add_files(
[
{
file_path: '.gitlab-ci.yml',
content: <<~YAML
variables:
EXTRA_ARGS: "-f $TEST_FILE"
DOCKER_REMOTE_ARGS: --tlscacert="$DOCKER_CA_CERT"
EXTRACTED_CRT_FILE: ${DOCKER_CA_CERT}.crt
MY_FILE_VAR: $TEST_FILE
test:
tags: [#{executor}]
script:
- echo "run something $EXTRA_ARGS"
- echo "docker run $DOCKER_REMOTE_ARGS"
- echo "run --output=$EXTRACTED_CRT_FILE"
- echo "Will read private key from $MY_FILE_VAR"
YAML
}
]
)
end
end
let(:add_file_variables) do
{
'TEST_FILE' => 'hello, this is test',
'DOCKER_CA_CERT' => 'This is secret'
}.each do |file_name, content|
add_file_variable_to_project(file_name, content)
end
end
before do
add_file_variables
add_ci_file
trigger_pipeline
wait_for_pipeline
end
after do
runner.remove_via_api!
end
it 'shows in job log accordingly', testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/370791' do
job = Resource::Job.fabricate_via_api! do |job|
job.project = project
job.id = project.job_by_name('test')[:id]
end
aggregate_failures do
trace = job.trace
expect(trace).to have_content('run something -f hello, this is test')
expect(trace).to have_content('docker run --tlscacert="This is secret"')
expect(trace).to have_content('run --output=This is secret.crt')
expect(trace).to have_content('Will read private key from hello, this is test')
end
end
private
def add_file_variable_to_project(key, value)
Resource::CiVariable.fabricate_via_api! do |ci_variable|
ci_variable.project = project
ci_variable.key = key
ci_variable.value = value
ci_variable.variable_type = 'file'
end
end
def trigger_pipeline
Resource::Pipeline.fabricate_via_api! do |pipeline|
pipeline.project = project
end
end
def wait_for_pipeline
Support::Waiter.wait_until do
project.pipelines.present? && project.pipelines.first[:status] == 'success'
end
end
end
end
end
|