-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunner_test.go
88 lines (72 loc) · 1.99 KB
/
runner_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package concourse_test
import (
"errors"
"io"
"strings"
"github.com/go-playground/validator/v10"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/suhlig/concourse-resource-go"
)
// These tests ensure that validation is being _invoked_ on request and response.
// The actual validations are tested more exhaustively in validation_test.go.
var _ = Describe("Check Validation", func() {
var (
err error
resource concourse.Resource[Source, Version, Params]
stdin io.Reader
stdout, stderr io.Writer
)
BeforeEach(func() {
stdout = &strings.Builder{}
stderr = &strings.Builder{}
})
JustBeforeEach(func(ctx SpecContext) {
err = concourse.CheckWithValidation[Source, Version, Params](ctx, resource, stdin, stdout, stderr)
})
Context("valid request", func() {
BeforeEach(func() {
resource = NullResource[Source, Version, Params]{}
stdin = strings.NewReader(`{
"source": {
"url": "https://example.com",
"version": {
"number": 2
}
}
}`)
})
It("works", func() {
Expect(err).ToNot(HaveOccurred())
})
Context("invalid response", func() {
BeforeEach(func() {
resource = Troublemaker[Source, Version, Params]{}
})
It("fails", func() {
Expect(err).To(HaveOccurred())
})
It("provides a reasonable message", func() {
Expect(err.Error()).To(ContainSubstring("Field validation for 'Number' failed on the 'max' tag"))
})
})
})
Context("invalid request", func() {
BeforeEach(func() {
stdin = strings.NewReader(`{"source": { "url": "null" }}`)
})
It("fails", func() {
Expect(err).To(HaveOccurred())
})
Context("validation error", func() {
var validationErrors validator.ValidationErrors
JustBeforeEach(func() {
validationErrors = errors.Unwrap(err).(validator.ValidationErrors)
})
It("has the expected error", func() {
Expect(validationErrors[0].Field()).To(Equal("URL"))
Expect(validationErrors[0].Tag()).To(Equal("http_url"))
})
})
})
})