11package validate
22
33import (
4- "os "
4+ _ "embed "
55 "testing"
66
77 "go.lsp.dev/protocol"
88)
99
10+ var (
11+ //go:embed testdata/valid_checkout_method.yml
12+ validCheckoutMethodYml string
13+
14+ //go:embed testdata/invalid_checkout_method.yml
15+ invalidCheckoutMethodYml string
16+
17+ //go:embed testdata/invalid_checkout_method_shallow.yml
18+ invalidCheckoutMethodShallowYml string
19+
20+ //go:embed testdata/valid_checkout_method_shallow.yml
21+ validCheckoutMethodShallowYml string
22+ )
23+
1024func TestStepsValidation (t * testing.T ) {
1125 testCases := []ValidateTestCase {
1226 {
@@ -72,27 +86,15 @@ workflows:
7286}
7387
7488func TestYamlDocument_parseCheckout (t * testing.T ) {
75- validConfigFilePath := "./testdata/valid_checkout_method.yml"
76- validConfig , err := os .ReadFile (validConfigFilePath )
77- if err != nil {
78- t .Fatal ("Failed to read valid_checkout_method.yml" )
79- }
80-
81- invalidConfigFilePath := "./testdata/invalid_checkout_method.yml"
82- invalidConfig , err := os .ReadFile (invalidConfigFilePath )
83- if err != nil {
84- t .Fatal ("Failed to read invalid_checkout_method.yml" )
85- }
86-
8789 testCases := []ValidateTestCase {
8890 {
8991 Name : "Specifying checkout method full does not result in an error" ,
90- YamlContent : string ( validConfig ) ,
92+ YamlContent : validCheckoutMethodYml ,
9193 Diagnostics : []protocol.Diagnostic {},
9294 },
9395 {
9496 Name : "Specifying an invalid checkout method results in an error" ,
95- YamlContent : string ( invalidConfig ) ,
97+ YamlContent : invalidCheckoutMethodYml ,
9698 Diagnostics : []protocol.Diagnostic {
9799 {
98100 Severity : protocol .DiagnosticSeverityError ,
@@ -102,6 +104,33 @@ func TestYamlDocument_parseCheckout(t *testing.T) {
102104 },
103105 Message : "Checkout method 'invalid' is invalid" ,
104106 },
107+ {
108+ Severity : protocol .DiagnosticSeverityError ,
109+ Range : protocol.Range {
110+ Start : protocol.Position {Line : 7 , Character : 8 },
111+ End : protocol.Position {Line : 7 , Character : 16 },
112+ },
113+ Message : "Checkout depth can only be used with the shallow checkout method" ,
114+ },
115+ },
116+ },
117+ {
118+ Name : "Specifying checkout method shallow with depth does not result in an error" ,
119+ YamlContent : validCheckoutMethodShallowYml ,
120+ Diagnostics : []protocol.Diagnostic {},
121+ },
122+ {
123+ Name : "Specifying checkout method shallow without depth results in an error" ,
124+ YamlContent : invalidCheckoutMethodShallowYml ,
125+ Diagnostics : []protocol.Diagnostic {
126+ {
127+ Severity : protocol .DiagnosticSeverityError ,
128+ Range : protocol.Range {
129+ Start : protocol.Position {Line : 7 , Character : 8 },
130+ End : protocol.Position {Line : 7 , Character : 16 },
131+ },
132+ Message : "Checkout depth must be a valid integer when using the shallow checkout method" ,
133+ },
105134 },
106135 },
107136 }
0 commit comments