-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec_test.go
48 lines (36 loc) · 1.17 KB
/
spec_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
package chevron
import (
"context"
"net/http"
"github.com/aphistic/sweet"
"github.com/efritz/response"
"github.com/go-nacelle/nacelle"
. "github.com/onsi/gomega"
)
type SpecSuite struct{}
func (s *SpecSuite) TestEmptySpecComposition(t sweet.T) {
// Static test for conformance to interface
var ts ResourceSpec = &TestSpec{}
// Show that we can "override" a method
resp := ts.Get(testBackground(), nil, nil)
Expect(resp.StatusCode()).To(Equal(http.StatusOK))
// Check response
_, data, err := response.Serialize(resp)
Expect(err).To(BeNil())
Expect(data).To(MatchJSON(`["foo", "bar", "baz"]`))
// The remaining methods should fall through to the default
for _, handler := range []Handler{ts.Options, ts.Post, ts.Put, ts.Patch, ts.Delete} {
Expect(handler(testBackground(), nil, nil).StatusCode()).To(Equal(http.StatusMethodNotAllowed))
}
}
func testBackground() context.Context {
return setNotImplementedHandler(context.Background(), defaultNotImplementedHandler)
}
//
//
type TestSpec struct {
*EmptySpec
}
func (ts *TestSpec) Get(ctx context.Context, req *http.Request, logger nacelle.Logger) response.Response {
return response.JSON([]string{"foo", "bar", "baz"})
}