@@ -11,15 +11,27 @@ public class LintClientTests
1111 private const string ValidCIYaml = @"
1212variables:
1313 CI_DEBUG_TRACE: ""true""
14- build:
14+ build-job:
15+ stage: build
16+ tags:
17+ - Runner-Build
18+ before_script:
19+ - echo before start
20+ - echo before end
1521 script:
16- - echo test
22+ - echo test start
23+ - echo test end
24+ after_script:
25+ - echo after start
26+ - echo after end
27+ when: always
28+ allow_failure: true
1729" ;
1830
1931 private const string InvalidCIYaml = @"
2032variables:
2133 CI_DEBUG_TRACE: ""true""
22- build:
34+ build-job :
2335 script:
2436 - echo test
2537 this_key_should_not_exist:
@@ -36,9 +48,38 @@ public async Task LintValidCIYaml()
3648
3749 var result = await context . Client . Lint . ValidateCIYamlContentAsync ( project . Id . ToString ( ) , ValidCIYaml , new ( ) , CancellationToken . None ) ;
3850
39- Assert . That ( result . Valid , Is . True ) ;
40- Assert . That ( result . Errors . Length != 0 , Is . False ) ;
41- Assert . That ( result . Warnings . Length != 0 , Is . False ) ;
51+ Assert . Multiple ( ( ) =>
52+ {
53+ Assert . That ( result . Valid , Is . True ) ;
54+ Assert . That ( result . Errors , Is . Empty ) ;
55+ Assert . That ( result . Warnings , Is . Empty ) ;
56+ } ) ;
57+ }
58+
59+ [ Test ]
60+ [ NGitLabRetry ]
61+ public async Task LintValidCIYamlWithJobs ( )
62+ {
63+ using var context = await GitLabTestContext . CreateAsync ( ) ;
64+ var project = context . CreateProject ( ) ;
65+ var lintClient = context . Client . Lint ;
66+
67+ var result = await context . Client . Lint . ValidateCIYamlContentAsync ( project . Id . ToString ( ) , ValidCIYaml , new ( ) { IncludeJobs = true } , CancellationToken . None ) ;
68+
69+ Assert . That ( result . Jobs , Has . Length . EqualTo ( 1 ) ) ;
70+ var job = result . Jobs [ 0 ] ;
71+ Assert . Multiple ( ( ) =>
72+ {
73+ Assert . That ( job . Name , Is . EqualTo ( "build-job" ) ) ;
74+ Assert . That ( job . Stage , Is . EqualTo ( "build" ) ) ;
75+ Assert . That ( job . BeforeScript , Is . EqualTo ( [ "echo before start" , "echo before end" ] ) ) ;
76+ Assert . That ( job . Script , Is . EqualTo ( [ "echo test start" , "echo test end" ] ) ) ;
77+ Assert . That ( job . AfterScript , Is . EqualTo ( [ "echo after start" , "echo after end" ] ) ) ;
78+ Assert . That ( job . TagList , Is . EqualTo ( [ "Runner-Build" ] ) ) ;
79+ Assert . That ( job . Environment , Is . Null ) ;
80+ Assert . That ( job . When , Is . EqualTo ( "always" ) ) ;
81+ Assert . That ( job . AllowFailure , Is . True ) ;
82+ } ) ;
4283 }
4384
4485 [ Test ]
@@ -51,9 +92,12 @@ public async Task LintInvalidCIYaml()
5192
5293 var result = await context . Client . Lint . ValidateCIYamlContentAsync ( project . Id . ToString ( ) , InvalidCIYaml , new ( ) , CancellationToken . None ) ;
5394
54- Assert . That ( result . Valid , Is . False ) ;
55- Assert . That ( result . Errors . Length != 0 , Is . True ) ;
56- Assert . That ( result . Warnings . Length != 0 , Is . False ) ;
95+ Assert . Multiple ( ( ) =>
96+ {
97+ Assert . That ( result . Valid , Is . False ) ;
98+ Assert . That ( result . Errors , Is . Not . Empty ) ;
99+ Assert . That ( result . Warnings , Is . Empty ) ;
100+ } ) ;
57101 }
58102
59103 [ Test ]
@@ -74,9 +118,12 @@ public async Task LintValidCIProjectYaml()
74118
75119 var result = await context . Client . Lint . ValidateProjectCIConfigurationAsync ( project . Id . ToString ( ) , new ( ) , CancellationToken . None ) ;
76120
77- Assert . That ( result . Valid , Is . True ) ;
78- Assert . That ( result . Errors . Length != 0 , Is . False ) ;
79- Assert . That ( result . Warnings . Length != 0 , Is . False ) ;
121+ Assert . Multiple ( ( ) =>
122+ {
123+ Assert . That ( result . Valid , Is . True ) ;
124+ Assert . That ( result . Errors , Is . Empty ) ;
125+ Assert . That ( result . Warnings , Is . Empty ) ;
126+ } ) ;
80127 }
81128
82129 [ Test ]
@@ -97,8 +144,11 @@ public async Task LintInvalidProjectCIYaml()
97144
98145 var result = await context . Client . Lint . ValidateProjectCIConfigurationAsync ( project . Id . ToString ( ) , new ( ) , CancellationToken . None ) ;
99146
100- Assert . That ( result . Valid , Is . False ) ;
101- Assert . That ( result . Errors . Length != 0 , Is . True ) ;
102- Assert . That ( result . Warnings . Length != 0 , Is . False ) ;
147+ Assert . Multiple ( ( ) =>
148+ {
149+ Assert . That ( result . Valid , Is . False ) ;
150+ Assert . That ( result . Errors , Is . Not . Empty ) ;
151+ Assert . That ( result . Warnings , Is . Empty ) ;
152+ } ) ;
103153 }
104154}
0 commit comments