|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | 3 | // See the LICENSE file in the project root for more information. |
4 | 4 |
|
| 5 | +using Cake.Common.Build.GitLabCI.Data; |
5 | 6 | using Cake.Common.Tests.Fixtures.Build; |
| 7 | +using NSubstitute; |
6 | 8 | using Xunit; |
7 | 9 |
|
8 | 10 | namespace Cake.Common.Tests.Unit.Build.GitLabCI.Data |
@@ -362,5 +364,41 @@ public void Should_Return_Correct_Value() |
362 | 364 | Assert.Equal(42, result); |
363 | 365 | } |
364 | 366 | } |
| 367 | + |
| 368 | + public sealed class TheSourceProperty |
| 369 | + { |
| 370 | + // Values taken from https://docs.gitlab.com/ee/ci/jobs/job_rules.html#ci_pipeline_source-predefined-variable |
| 371 | + [Theory] |
| 372 | + [InlineData("", null)] |
| 373 | + [InlineData("unknown_source", null)] |
| 374 | + [InlineData("api", GitLabCIPipelineSource.Api)] |
| 375 | + [InlineData("chat", GitLabCIPipelineSource.Chat)] |
| 376 | + [InlineData("external", GitLabCIPipelineSource.External)] |
| 377 | + [InlineData("external_pull_request_event", GitLabCIPipelineSource.ExternalPullRequestEvent)] |
| 378 | + [InlineData("merge_request_event", GitLabCIPipelineSource.MergeRequestEvent)] |
| 379 | + [InlineData("ondemand_dast_scan", GitLabCIPipelineSource.OnDemandDastScan)] |
| 380 | + [InlineData("ondemand_dast_validation", GitLabCIPipelineSource.OnDemandDastValidation)] |
| 381 | + [InlineData("parent_pipeline", GitLabCIPipelineSource.ParentPipeline)] |
| 382 | + [InlineData("pipeline", GitLabCIPipelineSource.Pipeline)] |
| 383 | + [InlineData("push", GitLabCIPipelineSource.Push)] |
| 384 | + [InlineData("schedule", GitLabCIPipelineSource.Schedule)] |
| 385 | + [InlineData("security_orchestration_policy", GitLabCIPipelineSource.SecurityOrchestrationPolicy)] |
| 386 | + [InlineData("trigger", GitLabCIPipelineSource.Trigger)] |
| 387 | + [InlineData("web", GitLabCIPipelineSource.Web)] |
| 388 | + [InlineData("webide", GitLabCIPipelineSource.WebIde)] |
| 389 | + public void Should_Return_Correct_Value(string pipelineSourceEnvironmentVariable, GitLabCIPipelineSource? expectedSource) |
| 390 | + { |
| 391 | + // Given |
| 392 | + var fixture = new GitLabCIInfoFixture(); |
| 393 | + fixture.Environment.GetEnvironmentVariable("CI_PIPELINE_SOURCE").Returns(pipelineSourceEnvironmentVariable); |
| 394 | + var info = fixture.CreateBuildInfo(); |
| 395 | + |
| 396 | + // When |
| 397 | + var result = info.Source; |
| 398 | + |
| 399 | + // Then |
| 400 | + Assert.Equal(expectedSource, result); |
| 401 | + } |
| 402 | + } |
365 | 403 | } |
366 | 404 | } |
0 commit comments