Skip to content

Commit 6a403a7

Browse files
committed
feat: Update checkout validation messages and add test cases for shallow method
1 parent 625091b commit 6a403a7

File tree

5 files changed

+86
-17
lines changed

5 files changed

+86
-17
lines changed

pkg/parser/validate/steps.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,19 @@ func (val Validate) validateCheckout(step ast.Checkout) {
229229

230230
if step.Method == "shallow" {
231231
depth, err := strconv.Atoi(step.Depth)
232-
if err != nil || depth <= 0 {
232+
if err != nil {
233+
val.addDiagnostic(protocol.Diagnostic{
234+
Severity: protocol.DiagnosticSeverityError,
235+
Range: step.Range,
236+
Message: "Checkout depth must be a valid integer when using the shallow checkout method",
237+
})
238+
return
239+
}
240+
if depth <= 0 {
233241
val.addDiagnostic(protocol.Diagnostic{
234242
Severity: protocol.DiagnosticSeverityError,
235243
Range: step.Range,
236-
Message: "Checkout depth must be a positive integer",
244+
Message: "Checkout depth must be a positive integer when using the shallow checkout method",
237245
})
238246
}
239247
}

pkg/parser/validate/steps_test.go

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
package validate
22

33
import (
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+
1024
func TestStepsValidation(t *testing.T) {
1125
testCases := []ValidateTestCase{
1226
{
@@ -72,27 +86,15 @@ workflows:
7286
}
7387

7488
func 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
}

pkg/parser/validate/testdata/invalid_checkout_method.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ jobs:
77
steps:
88
- checkout:
99
method: "invalid"
10+
depth: 1
1011
- run: echo "hello world"
1112

1213
workflows:
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: 2.1
2+
3+
jobs:
4+
build:
5+
docker:
6+
- image: cimg/base:stable
7+
steps:
8+
- checkout:
9+
method: shallow
10+
- run: echo "hello world"
11+
12+
workflows:
13+
test-build:
14+
jobs:
15+
- build
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: 2.1
2+
3+
jobs:
4+
build:
5+
docker:
6+
- image: cimg/base:stable
7+
steps:
8+
- checkout:
9+
method: shallow
10+
depth: 1
11+
- run: echo "hello world"
12+
13+
workflows:
14+
test-build:
15+
jobs:
16+
- build

0 commit comments

Comments
 (0)