builds.rb 5.31 KB
Newer Older
1 2
include ActionDispatch::TestProcess

3
FactoryBot.define do
4
  factory :ci_build, class: Ci::Build do
5
    name 'test'
6 7
    stage 'test'
    stage_idx 0
8 9
    ref 'master'
    tag false
Kamil Trzcinski's avatar
Kamil Trzcinski committed
10
    commands 'ls -a'
11
    protected false
12 13
    created_at 'Di 29. Okt 09:50:00 CET 2013'
    pending
14

15 16
    options do
      {
17 18
        image: 'ruby:2.1',
        services: ['postgres']
19 20
      }
    end
21

22 23
    yaml_variables do
      [
24
        { key: 'DB_NAME', value: 'postgres', public: true }
25 26
      ]
    end
27

28
    pipeline factory: :ci_pipeline
29

30 31 32 33 34 35 36 37 38
    trait :started do
      started_at 'Di 29. Okt 09:51:28 CET 2013'
    end

    trait :finished do
      started
      finished_at 'Di 29. Okt 09:53:28 CET 2013'
    end

39
    trait :success do
40
      finished
41 42 43 44
      status 'success'
    end

    trait :failed do
45
      finished
46 47 48
      status 'failed'
    end

49
    trait :canceled do
50
      finished
51 52 53
      status 'canceled'
    end

54
    trait :skipped do
55
      started
56 57 58
      status 'skipped'
    end

59
    trait :running do
60
      started
61 62 63 64
      status 'running'
    end

    trait :pending do
65
      queued_at 'Di 29. Okt 09:50:59 CET 2013'
66 67 68
      status 'pending'
    end

69 70 71 72
    trait :created do
      status 'created'
    end

73
    trait :manual do
74
      status 'manual'
75 76 77
      self.when 'manual'
    end

78
    trait :teardown_environment do
79 80
      environment 'staging'
      options environment: { name: 'staging',
81 82
                             action: 'stop',
                             url: 'http://staging.example.com/$CI_JOB_NAME' }
83 84
    end

85 86 87 88
    trait :allowed_to_fail do
      allow_failure true
    end

89 90 91 92
    trait :ignored do
      allowed_to_fail
    end

93 94 95 96
    trait :playable do
      manual
    end

97 98 99 100
    trait :retryable do
      success
    end

101 102 103 104
    trait :retried do
      retried true
    end

105 106 107 108 109 110 111 112 113
    trait :cancelable do
      pending
    end

    trait :erasable do
      success
      artifacts
    end

114 115 116 117
    trait :tags do
      tag_list [:docker, :ruby]
    end

118 119 120 121 122
    trait :on_tag do
      tag true
    end

    trait :triggered do
123
      trigger_request factory: :ci_trigger_request
124 125
    end

126
    after(:build) do |build, evaluator|
127
      build.project ||= build.pipeline.project
128 129
    end

130
    trait :tag do
131 132
      tag true
    end
133

134
    trait :coverage do
135
      coverage 99.9
136
      coverage_regex '/(d+)/'
137 138
    end

139
    trait :trace_live do
140
      after(:create) do |build, evaluator|
141
        build.trace.set('BUILD TRACE')
142
      end
143
    end
144

145 146 147 148 149 150
    trait :trace_artifact do
      after(:create) do |build, evaluator|
        create(:ci_job_artifact, :trace, job: build)
      end
    end

151
    trait :unicode_trace_live do
152 153 154 155 156 157 158 159 160
      after(:create) do |build, evaluator|
        trace = File.binread(
          File.expand_path(
            Rails.root.join('spec/fixtures/trace/ansi-sequence-and-unicode')))

        build.trace.set(trace)
      end
    end

161
    trait :erased do
162
      erased_at { Time.now }
163 164 165 166
      erased_by factory: :user
    end

    trait :queued do
167
      queued_at { Time.now }
168 169 170
      runner factory: :ci_runner
    end

171 172 173 174 175 176 177 178 179 180 181
    trait :legacy_artifacts do
      after(:create) do |build, _|
        build.update!(
          legacy_artifacts_file: fixture_file_upload(
            Rails.root.join('spec/fixtures/ci_build_artifacts.zip'), 'application/zip'),
          legacy_artifacts_metadata: fixture_file_upload(
            Rails.root.join('spec/fixtures/ci_build_artifacts_metadata.gz'), 'application/x-gzip')
        )
      end
    end

182
    trait :artifacts do
183
      after(:create) do |build|
184 185
        create(:ci_job_artifact, :archive, job: build, expire_at: build.artifacts_expire_at)
        create(:ci_job_artifact, :metadata, job: build, expire_at: build.artifacts_expire_at)
186
        build.reload
187
      end
188
    end
189

190
    trait :test_reports do
191 192
      after(:build) do |build|
        build.job_artifacts << create(:ci_job_artifact, :junit, job: build)
193 194 195
      end
    end

196
    trait :expired do
197
      artifacts_expire_at { 1.minute.ago }
198
    end
199 200 201 202 203 204 205 206 207 208 209 210

    trait :with_commit do
      after(:build) do |build|
        allow(build).to receive(:commit).and_return build(:commit, :without_author)
      end
    end

    trait :with_commit_and_author do
      after(:build) do |build|
        allow(build).to receive(:commit).and_return build(:commit)
      end
    end
211 212 213 214

    trait :extended_options do
      options do
        {
215
            image: { name: 'ruby:2.1', entrypoint: '/bin/sh' },
216
            services: ['postgres', { name: 'docker:stable-dind', entrypoint: '/bin/sh', command: 'sleep 30', alias: 'docker' }],
217
            after_script: %w(ls date),
218 219 220 221 222 223 224 225 226 227
            artifacts: {
                name: 'artifacts_file',
                untracked: false,
                paths: ['out/'],
                when: 'always',
                expire_in: '7d'
            },
            cache: {
                key: 'cache_key',
                untracked: false,
228 229
                paths: ['vendor/*'],
                policy: 'pull-push'
230 231 232 233
            }
        }
      end
    end
234 235 236 237

    trait :no_options do
      options { {} }
    end
Filipa Lacerda's avatar
Filipa Lacerda committed
238 239 240 241 242

    trait :non_playable do
      status 'created'
      self.when 'manual'
    end
Shinya Maeda's avatar
Shinya Maeda committed
243

244
    trait :protected do
Shinya Maeda's avatar
Shinya Maeda committed
245 246
      protected true
    end
247 248 249 250 251

    trait :script_failure do
      failed
      failure_reason 1
    end
252 253 254 255 256

    trait :api_failure do
      failed
      failure_reason 2
    end
257 258 259 260 261 262

    trait :with_runner_session do
      after(:build) do |build|
        build.build_runner_session(url: 'ws://localhost')
      end
    end
263 264
  end
end