gitlab_ci_yaml_processor_spec.rb 26.5 KB
Newer Older
D
Douwe Maan 已提交
1 2
require 'spec_helper'

V
Valery Sizov 已提交
3
module Ci
D
Douwe Maan 已提交
4
  describe GitlabCiYamlProcessor, lib: true do
5
    let(:path) { 'path' }
6

V
Valery Sizov 已提交
7 8 9 10 11 12 13 14 15
    describe "#builds_for_ref" do
      let(:type) { 'test' }

      it "returns builds if no branch specified" do
        config = YAML.dump({
          before_script: ["pwd"],
          rspec: { script: "rspec" }
        })

16
        config_processor = GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
17 18 19 20

        expect(config_processor.builds_for_stage_and_ref(type, "master").size).to eq(1)
        expect(config_processor.builds_for_stage_and_ref(type, "master").first).to eq({
          stage: "test",
21
          stage_idx: 1,
V
Valery Sizov 已提交
22 23 24
          except: nil,
          name: :rspec,
          only: nil,
K
Kamil Trzcinski 已提交
25 26
          commands: "pwd\nrspec",
          tag_list: [],
V
Valery Sizov 已提交
27
          options: {},
K
Kamil Trzcinski 已提交
28 29
          allow_failure: false,
          when: "on_success"
V
Valery Sizov 已提交
30 31
        })
      end
32

33 34 35 36 37 38
      describe :only do
        it "does not return builds if only has another branch" do
          config = YAML.dump({
                               before_script: ["pwd"],
                               rspec: { script: "rspec", only: ["deploy"] }
                             })
V
Valery Sizov 已提交
39

40
          config_processor = GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
41

42 43
          expect(config_processor.builds_for_stage_and_ref(type, "master").size).to eq(0)
        end
V
Valery Sizov 已提交
44

45 46 47 48 49
        it "does not return builds if only has regexp with another branch" do
          config = YAML.dump({
                               before_script: ["pwd"],
                               rspec: { script: "rspec", only: ["/^deploy$/"] }
                             })
V
Valery Sizov 已提交
50

51
          config_processor = GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
52

53 54
          expect(config_processor.builds_for_stage_and_ref(type, "master").size).to eq(0)
        end
V
Valery Sizov 已提交
55

56 57 58 59 60
        it "returns builds if only has specified this branch" do
          config = YAML.dump({
                               before_script: ["pwd"],
                               rspec: { script: "rspec", only: ["master"] }
                             })
V
Valery Sizov 已提交
61

62
          config_processor = GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
63

64 65
          expect(config_processor.builds_for_stage_and_ref(type, "master").size).to eq(1)
        end
V
Valery Sizov 已提交
66

67 68 69 70 71
        it "returns builds if only has a list of branches including specified" do
          config = YAML.dump({
                               before_script: ["pwd"],
                               rspec: { script: "rspec", type: type, only: ["master", "deploy"] }
                             })
V
Valery Sizov 已提交
72

73
          config_processor = GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
74

75 76
          expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(1)
        end
V
Valery Sizov 已提交
77

78 79 80 81 82
        it "returns builds if only has a branches keyword specified" do
          config = YAML.dump({
                               before_script: ["pwd"],
                               rspec: { script: "rspec", type: type, only: ["branches"] }
                             })
V
Valery Sizov 已提交
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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
          config_processor = GitlabCiYamlProcessor.new(config, path)

          expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(1)
        end

        it "does not return builds if only has a tags keyword" do
          config = YAML.dump({
                               before_script: ["pwd"],
                               rspec: { script: "rspec", type: type, only: ["tags"] }
                             })

          config_processor = GitlabCiYamlProcessor.new(config, path)

          expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(0)
        end

        it "returns builds if only has current repository path" do
          config = YAML.dump({
                               before_script: ["pwd"],
                               rspec: { script: "rspec", type: type, only: ["branches@path"] }
                             })

          config_processor = GitlabCiYamlProcessor.new(config, path)

          expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(1)
        end

        it "does not return builds if only has different repository path" do
          config = YAML.dump({
                               before_script: ["pwd"],
                               rspec: { script: "rspec", type: type, only: ["branches@fork"] }
                             })

          config_processor = GitlabCiYamlProcessor.new(config, path)

          expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(0)
        end

        it "returns build only for specified type" do

          config = YAML.dump({
                               before_script: ["pwd"],
K
Kamil Trzcinski 已提交
126
                               rspec: { script: "rspec", type: "test", only: ["master", "deploy"] },
127 128 129
                               staging: { script: "deploy", type: "deploy", only: ["master", "deploy"] },
                               production: { script: "deploy", type: "deploy", only: ["master@path", "deploy"] },
                             })
V
Valery Sizov 已提交
130

K
Kamil Trzcinski 已提交
131
          config_processor = GitlabCiYamlProcessor.new(config, 'fork')
V
Valery Sizov 已提交
132

133
          expect(config_processor.builds_for_stage_and_ref("deploy", "deploy").size).to eq(2)
K
Kamil Trzcinski 已提交
134 135
          expect(config_processor.builds_for_stage_and_ref("test", "deploy").size).to eq(1)
          expect(config_processor.builds_for_stage_and_ref("deploy", "master").size).to eq(1)
136
        end
V
Valery Sizov 已提交
137 138
      end

139 140 141 142 143 144
      describe :except do
        it "returns builds if except has another branch" do
          config = YAML.dump({
                               before_script: ["pwd"],
                               rspec: { script: "rspec", except: ["deploy"] }
                             })
V
Valery Sizov 已提交
145

146
          config_processor = GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
147

148 149 150 151 152 153 154 155 156 157 158 159 160
          expect(config_processor.builds_for_stage_and_ref(type, "master").size).to eq(1)
        end

        it "returns builds if except has regexp with another branch" do
          config = YAML.dump({
                               before_script: ["pwd"],
                               rspec: { script: "rspec", except: ["/^deploy$/"] }
                             })

          config_processor = GitlabCiYamlProcessor.new(config, path)

          expect(config_processor.builds_for_stage_and_ref(type, "master").size).to eq(1)
        end
V
Valery Sizov 已提交
161

162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
        it "does not return builds if except has specified this branch" do
          config = YAML.dump({
                               before_script: ["pwd"],
                               rspec: { script: "rspec", except: ["master"] }
                             })

          config_processor = GitlabCiYamlProcessor.new(config, path)

          expect(config_processor.builds_for_stage_and_ref(type, "master").size).to eq(0)
        end

        it "does not return builds if except has a list of branches including specified" do
          config = YAML.dump({
                               before_script: ["pwd"],
                               rspec: { script: "rspec", type: type, except: ["master", "deploy"] }
                             })

          config_processor = GitlabCiYamlProcessor.new(config, path)

          expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(0)
        end

        it "does not return builds if except has a branches keyword specified" do
          config = YAML.dump({
                               before_script: ["pwd"],
                               rspec: { script: "rspec", type: type, except: ["branches"] }
                             })

          config_processor = GitlabCiYamlProcessor.new(config, path)

          expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(0)
        end

        it "returns builds if except has a tags keyword" do
          config = YAML.dump({
                               before_script: ["pwd"],
                               rspec: { script: "rspec", type: type, except: ["tags"] }
                             })

          config_processor = GitlabCiYamlProcessor.new(config, path)

          expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(1)
        end

        it "does not return builds if except has current repository path" do
          config = YAML.dump({
                               before_script: ["pwd"],
                               rspec: { script: "rspec", type: type, except: ["branches@path"] }
                             })

          config_processor = GitlabCiYamlProcessor.new(config, path)

          expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(0)
        end

        it "returns builds if except has different repository path" do
          config = YAML.dump({
                               before_script: ["pwd"],
                               rspec: { script: "rspec", type: type, except: ["branches@fork"] }
                             })

          config_processor = GitlabCiYamlProcessor.new(config, path)

          expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(1)
        end

        it "returns build except specified type" do
          config = YAML.dump({
                               before_script: ["pwd"],
K
Kamil Trzcinski 已提交
231 232 233
                               rspec: { script: "rspec", type: "test", except: ["master", "deploy", "test@fork"] },
                               staging: { script: "deploy", type: "deploy", except: ["master"] },
                               production: { script: "deploy", type: "deploy", except: ["master@fork"] },
234 235
                             })

K
Kamil Trzcinski 已提交
236
          config_processor = GitlabCiYamlProcessor.new(config, 'fork')
237

K
Kamil Trzcinski 已提交
238 239 240
          expect(config_processor.builds_for_stage_and_ref("deploy", "deploy").size).to eq(2)
          expect(config_processor.builds_for_stage_and_ref("test", "test").size).to eq(0)
          expect(config_processor.builds_for_stage_and_ref("deploy", "master").size).to eq(0)
241
        end
V
Valery Sizov 已提交
242
      end
243

D
Douwe Maan 已提交
244 245
    end

V
Valery Sizov 已提交
246 247 248 249 250 251 252 253 254
    describe "Image and service handling" do
      it "returns image and service when defined" do
        config = YAML.dump({
                             image: "ruby:2.1",
                             services: ["mysql"],
                             before_script: ["pwd"],
                             rspec: { script: "rspec" }
                           })

255
        config_processor = GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
256 257 258 259 260

        expect(config_processor.builds_for_stage_and_ref("test", "master").size).to eq(1)
        expect(config_processor.builds_for_stage_and_ref("test", "master").first).to eq({
          except: nil,
          stage: "test",
261
          stage_idx: 1,
V
Valery Sizov 已提交
262 263
          name: :rspec,
          only: nil,
K
Kamil Trzcinski 已提交
264 265
          commands: "pwd\nrspec",
          tag_list: [],
V
Valery Sizov 已提交
266 267 268 269
          options: {
            image: "ruby:2.1",
            services: ["mysql"]
          },
270 271
          allow_failure: false,
          when: "on_success"
V
Valery Sizov 已提交
272 273 274 275 276 277 278 279 280 281 282
        })
      end

      it "returns image and service when overridden for job" do
        config = YAML.dump({
                             image:         "ruby:2.1",
                             services:      ["mysql"],
                             before_script: ["pwd"],
                             rspec:         { image: "ruby:2.5", services: ["postgresql"], script: "rspec" }
                           })

283
        config_processor = GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
284 285 286 287 288

        expect(config_processor.builds_for_stage_and_ref("test", "master").size).to eq(1)
        expect(config_processor.builds_for_stage_and_ref("test", "master").first).to eq({
          except: nil,
          stage: "test",
289
          stage_idx: 1,
V
Valery Sizov 已提交
290 291
          name: :rspec,
          only: nil,
K
Kamil Trzcinski 已提交
292 293
          commands: "pwd\nrspec",
          tag_list: [],
V
Valery Sizov 已提交
294 295 296 297
          options: {
            image: "ruby:2.5",
            services: ["postgresql"]
          },
298 299
          allow_failure: false,
          when: "on_success"
V
Valery Sizov 已提交
300 301
        })
      end
D
Douwe Maan 已提交
302 303
    end

V
Valery Sizov 已提交
304 305 306 307 308 309 310 311 312 313 314 315
    describe "Variables" do
      it "returns variables when defined" do
        variables = {
          var1: "value1",
          var2: "value2",
        }
        config = YAML.dump({
                             variables: variables,
                             before_script: ["pwd"],
                             rspec: { script: "rspec" }
                           })

316
        config_processor = GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
317 318
        expect(config_processor.variables).to eq(variables)
      end
D
Douwe Maan 已提交
319 320
    end

321 322 323 324 325 326 327
    describe "When" do
      %w(on_success on_failure always).each do |when_state|
        it "returns #{when_state} when defined" do
          config = YAML.dump({
                               rspec: { script: "rspec", when: when_state }
                             })

328
          config_processor = GitlabCiYamlProcessor.new(config, path)
329 330 331 332 333 334 335
          builds = config_processor.builds_for_stage_and_ref("test", "master")
          expect(builds.size).to eq(1)
          expect(builds.first[:when]).to eq(when_state)
        end
      end
    end

336 337 338
    describe "Caches" do
      it "returns cache when defined globally" do
        config = YAML.dump({
339
                             cache: { paths: ["logs/", "binaries/"], untracked: true, key: 'key' },
340 341 342 343 344 345 346 347 348 349 350
                             rspec: {
                               script: "rspec"
                             }
                           })

        config_processor = GitlabCiYamlProcessor.new(config)

        expect(config_processor.builds_for_stage_and_ref("test", "master").size).to eq(1)
        expect(config_processor.builds_for_stage_and_ref("test", "master").first[:options][:cache]).to eq(
          paths: ["logs/", "binaries/"],
          untracked: true,
351
          key: 'key',
352 353 354 355 356 357
        )
      end

      it "returns cache when defined in a job" do
        config = YAML.dump({
                             rspec: {
358
                               cache: { paths: ["logs/", "binaries/"], untracked: true, key: 'key' },
359 360 361 362 363 364 365 366 367 368
                               script: "rspec"
                             }
                           })

        config_processor = GitlabCiYamlProcessor.new(config)

        expect(config_processor.builds_for_stage_and_ref("test", "master").size).to eq(1)
        expect(config_processor.builds_for_stage_and_ref("test", "master").first[:options][:cache]).to eq(
          paths: ["logs/", "binaries/"],
          untracked: true,
369
          key: 'key',
370 371 372 373 374
        )
      end

      it "overwrite cache when defined for a job and globally" do
        config = YAML.dump({
375
                             cache: { paths: ["logs/", "binaries/"], untracked: true, key: 'global' },
376 377
                             rspec: {
                               script: "rspec",
378
                               cache: { paths: ["test/"], untracked: false, key: 'local' },
379 380 381 382 383 384 385 386 387
                             }
                           })

        config_processor = GitlabCiYamlProcessor.new(config)

        expect(config_processor.builds_for_stage_and_ref("test", "master").size).to eq(1)
        expect(config_processor.builds_for_stage_and_ref("test", "master").first[:options][:cache]).to eq(
          paths: ["test/"],
          untracked: false,
388
          key: 'local',
389 390 391 392
        )
      end
    end

K
Kamil Trzcinski 已提交
393 394 395 396 397 398
    describe "Artifacts" do
      it "returns artifacts when defined" do
        config = YAML.dump({
                             image:         "ruby:2.1",
                             services:      ["mysql"],
                             before_script: ["pwd"],
399 400 401 402
                             rspec:         {
                               artifacts: { paths: ["logs/", "binaries/"], untracked: true },
                               script: "rspec"
                             }
K
Kamil Trzcinski 已提交
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
                           })

        config_processor = GitlabCiYamlProcessor.new(config)

        expect(config_processor.builds_for_stage_and_ref("test", "master").size).to eq(1)
        expect(config_processor.builds_for_stage_and_ref("test", "master").first).to eq({
          except: nil,
          stage: "test",
          stage_idx: 1,
          name: :rspec,
          only: nil,
          commands: "pwd\nrspec",
          tag_list: [],
          options: {
            image: "ruby:2.1",
            services: ["mysql"],
419 420 421 422
            artifacts: {
              paths: ["logs/", "binaries/"],
              untracked: true
            }
K
Kamil Trzcinski 已提交
423 424 425 426 427 428 429
          },
          when: "on_success",
          allow_failure: false
        })
      end
    end

V
Valery Sizov 已提交
430
    describe "Error handling" do
431 432 433 434
      it "fails to parse YAML" do
        expect{GitlabCiYamlProcessor.new("invalid: yaml: test")}.to raise_error(Psych::SyntaxError)
      end

V
Valery Sizov 已提交
435
      it "indicates that object is invalid" do
436
        expect{GitlabCiYamlProcessor.new("invalid_yaml")}.to raise_error(GitlabCiYamlProcessor::ValidationError)
V
Valery Sizov 已提交
437 438 439 440 441
      end

      it "returns errors if tags parameter is invalid" do
        config = YAML.dump({ rspec: { script: "test", tags: "mysql" } })
        expect do
442
          GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
443 444 445 446 447 448
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: tags parameter should be an array of strings")
      end

      it "returns errors if before_script parameter is invalid" do
        config = YAML.dump({ before_script: "bundle update", rspec: { script: "test" } })
        expect do
449
          GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
450 451 452 453 454 455
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "before_script should be an array of strings")
      end

      it "returns errors if image parameter is invalid" do
        config = YAML.dump({ image: ["test"], rspec: { script: "test" } })
        expect do
456
          GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
457 458 459
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "image should be a string")
      end

K
Kamil Trzcinski 已提交
460 461 462
      it "returns errors if job name is blank" do
        config = YAML.dump({ '' => { script: "test" } })
        expect do
463
          GitlabCiYamlProcessor.new(config, path)
K
Kamil Trzcinski 已提交
464 465 466 467 468 469
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "job name should be non-empty string")
      end

      it "returns errors if job name is non-string" do
        config = YAML.dump({ 10 => { script: "test" } })
        expect do
470
          GitlabCiYamlProcessor.new(config, path)
K
Kamil Trzcinski 已提交
471 472 473
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "job name should be non-empty string")
      end

V
Valery Sizov 已提交
474 475 476
      it "returns errors if job image parameter is invalid" do
        config = YAML.dump({ rspec: { script: "test", image: ["test"] } })
        expect do
477
          GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
478 479 480 481 482 483
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: image should be a string")
      end

      it "returns errors if services parameter is not an array" do
        config = YAML.dump({ services: "test", rspec: { script: "test" } })
        expect do
484
          GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
485 486 487 488 489 490
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "services should be an array of strings")
      end

      it "returns errors if services parameter is not an array of strings" do
        config = YAML.dump({ services: [10, "test"], rspec: { script: "test" } })
        expect do
491
          GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
492 493 494 495 496 497
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "services should be an array of strings")
      end

      it "returns errors if job services parameter is not an array" do
        config = YAML.dump({ rspec: { script: "test", services: "test" } })
        expect do
498
          GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
499 500 501 502 503 504
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: services should be an array of strings")
      end

      it "returns errors if job services parameter is not an array of strings" do
        config = YAML.dump({ rspec: { script: "test", services: [10, "test"] } })
        expect do
505
          GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
506 507 508 509 510 511
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: services should be an array of strings")
      end

      it "returns errors if there are unknown parameters" do
        config = YAML.dump({ extra: "bundle update" })
        expect do
512
          GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
513 514 515 516 517 518
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Unknown parameter: extra")
      end

      it "returns errors if there are unknown parameters that are hashes, but doesn't have a script" do
        config = YAML.dump({ extra: { services: "test" } })
        expect do
519
          GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
520 521 522
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Unknown parameter: extra")
      end

523
      it "returns errors if there are no jobs defined" do
V
Valery Sizov 已提交
524 525
        config = YAML.dump({ before_script: ["bundle update"] })
        expect do
526
          GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
527 528 529 530 531 532
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Please define at least one job")
      end

      it "returns errors if job allow_failure parameter is not an boolean" do
        config = YAML.dump({ rspec: { script: "test", allow_failure: "string" } })
        expect do
533
          GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
534 535 536 537
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: allow_failure parameter should be an boolean")
      end

      it "returns errors if job stage is not a string" do
538
        config = YAML.dump({ rspec: { script: "test", type: 1 } })
V
Valery Sizov 已提交
539
        expect do
540
          GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
541 542 543 544
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test, deploy")
      end

      it "returns errors if job stage is not a pre-defined stage" do
545
        config = YAML.dump({ rspec: { script: "test", type: "acceptance" } })
V
Valery Sizov 已提交
546
        expect do
547
          GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
548 549 550 551
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test, deploy")
      end

      it "returns errors if job stage is not a defined stage" do
552
        config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", type: "acceptance" } })
V
Valery Sizov 已提交
553
        expect do
554
          GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
555 556 557 558 559 560
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test")
      end

      it "returns errors if stages is not an array" do
        config = YAML.dump({ types: "test", rspec: { script: "test" } })
        expect do
561
          GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
562 563 564 565 566 567
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "stages should be an array of strings")
      end

      it "returns errors if stages is not an array of strings" do
        config = YAML.dump({ types: [true, "test"], rspec: { script: "test" } })
        expect do
568
          GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
569 570 571 572 573 574
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "stages should be an array of strings")
      end

      it "returns errors if variables is not a map" do
        config = YAML.dump({ variables: "test", rspec: { script: "test" } })
        expect do
575
          GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
576 577 578 579 580 581
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-valued strings")
      end

      it "returns errors if variables is not a map of key-valued strings" do
        config = YAML.dump({ variables: { test: false }, rspec: { script: "test" } })
        expect do
582
          GitlabCiYamlProcessor.new(config, path)
V
Valery Sizov 已提交
583 584
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-valued strings")
      end
585 586

      it "returns errors if job when is not on_success, on_failure or always" do
K
Kamil Trzcinski 已提交
587
        config = YAML.dump({ rspec: { script: "test", when: 1 } })
588
        expect do
589
          GitlabCiYamlProcessor.new(config, path)
590 591
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: when parameter should be on_success, on_failure or always")
      end
K
Kamil Trzcinski 已提交
592

593 594
      it "returns errors if job artifacts:untracked is not an array of strings" do
        config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", artifacts: { untracked: "string" } } })
K
Kamil Trzcinski 已提交
595 596
        expect do
          GitlabCiYamlProcessor.new(config)
597 598 599 600 601 602 603 604
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: artifacts:untracked parameter should be an boolean")
      end

      it "returns errors if job artifacts:paths is not an array of strings" do
        config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", artifacts: { paths: "string" } } })
        expect do
          GitlabCiYamlProcessor.new(config)
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: artifacts:paths parameter should be an array of strings")
K
Kamil Trzcinski 已提交
605
      end
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620

      it "returns errors if cache:untracked is not an array of strings" do
        config = YAML.dump({ cache: { untracked: "string" }, rspec: { script: "test" } })
        expect do
          GitlabCiYamlProcessor.new(config)
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "cache:untracked parameter should be an boolean")
      end

      it "returns errors if cache:paths is not an array of strings" do
        config = YAML.dump({ cache: { paths: "string" }, rspec: { script: "test" } })
        expect do
          GitlabCiYamlProcessor.new(config)
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "cache:paths parameter should be an array of strings")
      end

621 622 623 624 625 626 627 628 629 630 631 632 633 634
      it "returns errors if cache:key is not a string" do
        config = YAML.dump({ cache: { key: 1 }, rspec: { script: "test" } })
        expect do
          GitlabCiYamlProcessor.new(config)
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "cache:key parameter should be a string")
      end

      it "returns errors if job cache:key is not an a string" do
        config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", cache: { key: 1 } } })
        expect do
          GitlabCiYamlProcessor.new(config)
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: cache:key parameter should be a string")
      end

635 636 637 638 639 640 641 642 643 644 645 646 647
      it "returns errors if job cache:untracked is not an array of strings" do
        config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", cache: { untracked: "string" } } })
        expect do
          GitlabCiYamlProcessor.new(config)
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: cache:untracked parameter should be an boolean")
      end

      it "returns errors if job cache:paths is not an array of strings" do
        config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", cache: { paths: "string" } } })
        expect do
          GitlabCiYamlProcessor.new(config)
        end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: cache:paths parameter should be an array of strings")
      end
D
Douwe Maan 已提交
648 649 650
    end
  end
end