@@ -11,49 +11,84 @@ import (
1111)
1212
1313func TestExecutorParam (t * testing.T ) {
14- yamlData := `jobs:
14+ testCases := []struct {
15+ label string
16+ yamlData string
17+ expectedDiag protocol.Diagnostic
18+ }{
19+ {
20+ label : "without default" ,
21+ yamlData : `jobs:
22+ test:
23+ parameters:
24+ os:
25+ type: executor
26+ executor: << parameters.os >>
27+ steps:
28+ - checkout` ,
29+ expectedDiag : protocol.Diagnostic {
30+ Range : protocol.Range {
31+ Start : protocol.Position {Line : 5 , Character : 4 },
32+ End : protocol.Position {Line : 5 , Character : 33 },
33+ },
34+ Severity : protocol .DiagnosticSeverityWarning ,
35+ },
36+ },
37+ {
38+ label : "with unknown default" ,
39+ yamlData : `jobs:
1540 test:
1641 parameters:
1742 os:
1843 type: executor
44+ default: unknown
1945 executor: << parameters.os >>
2046 steps:
21- - checkout`
22- ctx := & utils.LsContext {
23- Api : utils.ApiContext {
24- Token : "XXXXXXXXXXXX" ,
25- HostUrl : "https://circleci.com" ,
47+ - checkout` ,
48+ expectedDiag : protocol.Diagnostic {
49+ Range : protocol.Range {
50+ Start : protocol.Position {Line : 6 , Character : 4 },
51+ End : protocol.Position {Line : 6 , Character : 33 },
52+ },
53+ Severity : protocol .DiagnosticSeverityError ,
54+ },
2655 },
2756 }
28- doc , err := parser .ParseFromContent (
29- []byte (yamlData ),
30- ctx ,
31- uri .URI ("" ),
32- protocol.Position {},
33- )
34- assert .NoError (t , err , "invalid YAML data" )
35- assert .Contains (t , doc .Jobs , "test" )
3657
37- val := Validate {
38- Context : ctx ,
39- Doc : doc ,
40- Diagnostics : & []protocol.Diagnostic {},
41- }
42- val .validateSingleJob (doc .Jobs ["test" ])
58+ for _ , testCase := range testCases {
59+ t .Run ("executor parameter: " + testCase .label , func (t * testing.T ) {
4360
44- expectedDiag := protocol.Diagnostic {
45- Range : protocol.Range {
46- Start : protocol.Position {Line : 5 , Character : 4 },
47- End : protocol.Position {Line : 5 , Character : 33 },
48- },
49- Severity : protocol .DiagnosticSeverityError ,
50- }
51- for _ , diag := range * val .Diagnostics {
52- if diag .Range == expectedDiag .Range && diag .Severity == expectedDiag .Severity {
53- return
54- }
61+ ctx := & utils.LsContext {
62+ Api : utils.ApiContext {
63+ Token : "XXXXXXXXXXXX" ,
64+ HostUrl : "https://circleci.com" ,
65+ },
66+ }
67+ doc , err := parser .ParseFromContent (
68+ []byte (testCase .yamlData ),
69+ ctx ,
70+ uri .URI ("" ),
71+ protocol.Position {},
72+ )
73+ assert .NoError (t , err , "invalid YAML data" )
74+ assert .Contains (t , doc .Jobs , "test" )
75+
76+ val := Validate {
77+ Context : ctx ,
78+ Doc : doc ,
79+ Diagnostics : & []protocol.Diagnostic {},
80+ }
81+ val .validateSingleJob (doc .Jobs ["test" ])
82+
83+ for _ , diag := range * val .Diagnostics {
84+ if diag .Range == testCase .expectedDiag .Range &&
85+ diag .Severity == testCase .expectedDiag .Severity {
86+ return
87+ }
88+ }
89+ t .Fatalf (`missing "parameter as executor" diagnostic` )
90+ })
5591 }
56- t .Fatalf (`missing "parameter as executor" diagnostic` )
5792}
5893
5994func TestResourceClass (t * testing.T ) {
0 commit comments