실행 컨텍스트 선택
일부 테스트는 특정 환경에 대해 실행하거나 특정 파이프라인 또는 작업에서 실행되도록 설계됩니다. 우리는 only
및 except
메타데이터를 사용하여 테스트 실행 컨텍스트를 지정할 수 있습니다.
사용 가능한 스위치
스위치 | 기능 | 유형 |
---|---|---|
tld
| 최상위 도메인 매처 설정 | 문자열
|
subdomain
| 서브도메인 매처 설정 |
배열 또는 문자열
|
domain
| 도메인 매처 설정 | 문자열
|
production
| 프로덕션 환경과 일치 | 정적
|
pipeline
| 파이프라인 일치 |
배열 또는 정적
|
job
| 작업 일치 |
배열 또는 정적
|
경고:
production
및 { <switch>: 'value' }
를 동시에 지정할 수 없습니다.
이러한 옵션은 서로 배타적입니다. 프로덕션을 지정하려면 독립적으로 tld
및 domain
을 제어할 수 있습니다.
예제
Only
지정된 컨텍스트에서만 테스트를 실행합니다.
일치 항목:
- 환경을 위한 정규식
- 파이프라인을 위한 문자열 일치
- 작업을 위한 정규식 또는 문자열 일치
- 제네릭 조건에 대한 람다 또는 true/false 값
테스트 실행 컨텍스트 | 키 | 일치 항목 |
---|---|---|
gitlab.com
| only: :production
| gitlab.com
|
staging.gitlab.com
| only: { subdomain: :staging }
| (staging).+.com
|
gitlab.com and staging.gitlab.com
| only: { subdomain: /(staging.)?/, domain: 'gitlab' }
| (staging.)?gitlab.com
|
dev.gitlab.org
| only: { tld: '.org', domain: 'gitlab', subdomain: 'dev' }
| (dev).gitlab.org
|
staging.gitlab.com and domain.gitlab.com
| only: { subdomain: %i[staging domain] }
| (staging\|domain).+.com
|
nightly 파이프라인
| only: { pipeline: :nightly }
| “nightly scheduled pipeline” |
nightly 및 canary 파이프라인
| only: { pipeline: [:nightly, :canary] }
| “nightly scheduled pipeline” 및 “canary” |
ee:instance 작업
| only: { job: 'ee:instance' }
| 어떠한 파이프라인에서든 ee:instance 작업
|
모든 quarantine 작업
| only: { job: '.*quarantine' }
| 어떠한 파이프라인에서든 quarantine 으로 끝나는 작업
|
로컬 개발 환경 | only: :local
|
Runtime::Env.running_in_ci? 이 false인 어떠한 환경
|
조건이 true로 평가되는 경우 실행 | only: { condition: -> { ENV['TEST_ENV'] == 'true' } }
|
TEST_ENV 가 true로 설정된 경우 실행 가능
|
RSpec.describe 'Area' do
it 'runs in any environment or pipeline' do; end
it 'runs only in production environment', only: :production do; end
it 'runs only in staging environment', only: { subdomain: :staging } do; end
it 'runs in dev environment', only: { tld: '.org', domain: 'gitlab', subdomain: 'dev' } do; end
it 'runs in prod and staging environments', only: { subdomain: /(staging.)?/, domain: 'gitlab' } {}
it 'runs only in nightly pipeline', only: { pipeline: :nightly } do; end
it 'runs in nightly and canary pipelines', only: { pipeline: [:nightly, :canary] } do; end
it 'runs in specific environment matching condition', only: { condition: -> { ENV['TEST_ENV'] == 'true' } } do; end
end
Except
일반적으로 지정된 컨텍스트에서 제외하고 테스트를 실행합니다.
일치 항목:
- 환경을 위한 정규식
- 파이프라인을 위한 문자열 일치
- 작업을 위한 정규식 또는 문자열 일치
- 제네릭 조건에 대한 람다 또는 true/false 값
테스트 실행 컨텍스트 | 키 | 일치 항목 |
---|---|---|
gitlab.com
| except: :production
| gitlab.com
|
staging.gitlab.com
| except: { subdomain: :staging }
| (staging).+.com
|
gitlab.com and staging.gitlab.com
| except: { subdomain: /(staging.)?/, domain: 'gitlab' }
| (staging.)?gitlab.com
|
dev.gitlab.org
| except: { tld: '.org', domain: 'gitlab', subdomain: 'dev' }
| (dev).gitlab.org
|
staging.gitlab.com and domain.gitlab.com
| except: { subdomain: %i[staging domain] }
| (staging\|domain).+.com
|
nightly 파이프라인
| only: { pipeline: :nightly }
| “nightly scheduled pipeline” |
nightly 및 canary 파이프라인
| only: { pipeline: [:nightly, :canary] }
| “nightly scheduled pipeline” 및 “canary” |
ee:instance 작업
| except: { job: 'ee:instance' }
| 어떠한 파이프라인에서든 ee:instance 작업
|
모든 quarantine 작업
| except: { job: '.*quarantine' }
| 어떠한 파이프라인에서든 quarantine 으로 끝나는 작업
|
true로 평가되는 경우 실행하지 않음 | except: { condition: -> { ENV['TEST_ENV'] == 'true' } }
|
TEST_ENV 가 true로 설정된 경우 실행하지 않음
|
RSpec.describe 'Area' do
it 'runs in any execution context except the production environment', except: :production do; end
it 'runs in any execution context except the staging environment', except: { subdomain: :staging } do; end
it 'runs in any execution context except the nightly pipeline', except: { pipeline: :nightly } do; end
it 'runs in any execution context except the ee:instance job', except: { job: 'ee:instance' } do; end
it 'runs in specific environment not matching condition', except: { condition: -> { ENV['TEST_ENV'] == 'true' } } do; end
end
사용법 노트
테스트에 before
또는 after
블록이 있는 경우 외부 RSpec.describe
블록에 only
또는 except
메타데이터를 추가해야 합니다.
로컬 GitLab 인스턴스에서 only
로 태그된 테스트를 실행하려면 다음 중 하나를 수행할 수 있습니다:
-
CI_PROJECT_NAME
또는CI_JOB_NAME
환경 변수가 설정되어 있지 않은지 확인하세요. - 메타데이터에 맞는 변수를 설정하세요. 예를 들어, 메타데이터가
only: { pipeline: :nightly }
이면CI_PROJECT_NAME=nightly
으로 설정하세요. 메타데이터가only: { job: 'ee:instance' }
인 경우CI_JOB_NAME=ee:instance
으로 설정하세요. - 임시로 메타데이터를 제거하세요.
로컬에서 except
로 태그된 테스트를 실행하려면 다음 중 하나를 수행할 수 있습니다:
-
CI_PROJECT_NAME
또는CI_JOB_NAME
환경 변수가 설정되어 있지 않은지 확인하세요. - 임시로 메타데이터를 제거하세요.
특정 환경에 대한 테스트 격리
특정 환경에서만 테스트를 실행해야 하는 경우에는 해당 테스트를 격리할 수도 있습니다. 이 문법은 동일하지만, only: { ... }
해시가 quarantine: { ... }
해시에 중첩되는 것 외에는 동일합니다. 예를 들어, quarantine: { only: { subdomain: :staging } }
은 staging
에서 실행될 때만 해당 테스트를 격리합니다.
DISABLE_QUARANTINE
환경 변수를 사용하여 격리 기능을 명시적으로 비활성화할 수 있습니다. 이는 로컬에서 테스트를 실행할 때 유용합니다.