Skip to content

Commit 890a0c4

Browse files
authored
feat(mockery): allow PATCH requests (#4)
1 parent e823730 commit 890a0c4

File tree

6 files changed

+12
-14
lines changed

6 files changed

+12
-14
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
matrix:
1212
# support two latest major versions of Go, following the Go security policy
1313
# in which these versions get security updates. See https://golang.org/security
14-
go-version: [1.20.x, 1.21.x]
14+
go-version: [1.24.x, 1.25.x]
1515
steps:
1616
- uses: actions/checkout@v3
1717
- uses: actions/setup-go@v3

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.21.1-alpine3.18 AS builder
1+
FROM golang:1.25-alpine AS builder
22

33
RUN apk update && apk add --no-cache git
44

@@ -8,7 +8,7 @@ RUN go get ./
88
RUN CGO_ENABLED=0 go build -o /app/http-mockery
99
RUN chmod +x /app/http-mockery
1010

11-
FROM alpine:3.18
11+
FROM alpine:3.23
1212

1313
COPY --from=builder /app/http-mockery /go/bin/http-mockery
1414
RUN apk update && apk add --no-cache ca-certificates

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module github.com/UpCloudLtd/http-mockery
22

3-
go 1.21
3+
go 1.24
44

55
require (
6-
github.com/stretchr/testify v1.8.4
6+
github.com/stretchr/testify v1.11.1
77
github.com/valyala/fasttemplate v1.2.2
88
)
99

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
22
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
33
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
44
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5-
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
6-
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
5+
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
6+
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
77
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
88
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
99
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=

pkg/mockery/mockery.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ import (
1818
"github.com/valyala/fasttemplate"
1919
)
2020

21-
var (
22-
ErrEndpointNotFound = fmt.Errorf("no matching endpoint found")
23-
)
21+
var ErrEndpointNotFound = fmt.Errorf("no matching endpoint found")
2422

25-
var validHTTPMethods = []string{http.MethodGet, http.MethodPost, http.MethodPut, http.MethodPost, http.MethodDelete}
23+
var validHTTPMethods = []string{http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete, http.MethodPatch}
2624

2725
const (
2826
EndpointTypeNormal = "normal"
@@ -91,7 +89,7 @@ func (s MockHandler) ValidateConfig() error {
9189
}
9290
}
9391
if !validMethod {
94-
return fmt.Errorf(fmt.Sprintf("Invalid HTTP method (%s) for endpoint %s. Allowed: %+v", endpoint.Method, endpoint.Uri, validHTTPMethods))
92+
return fmt.Errorf("invalid HTTP method (%s) for endpoint %s. Allowed: %+v", endpoint.Method, endpoint.Uri, validHTTPMethods)
9593
}
9694

9795
validType := false
@@ -102,7 +100,7 @@ func (s MockHandler) ValidateConfig() error {
102100
}
103101
}
104102
if !validType {
105-
return fmt.Errorf(fmt.Sprintf("Invalid endpoint type (%s) for endpoint %s. Allowed: %+v", endpoint.Type, endpoint.Uri, validEndpointTypes))
103+
return fmt.Errorf("invalid endpoint type (%s) for endpoint %s. Allowed: %+v", endpoint.Type, endpoint.Uri, validEndpointTypes)
106104
}
107105

108106
if endpoint.Template != "" {

pkg/mockery/mockery_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func TestConfigValidation(t *testing.T) {
7575

7676
testMocker.Config.Endpoints[0].Method = "TRACE"
7777
err = testMocker.ValidateConfig()
78-
assert.ErrorContains(t, err, "Invalid HTTP method", "Config validation should fail on unsupported HTTP method")
78+
assert.ErrorContains(t, err, "invalid HTTP method", "Config validation should fail on unsupported HTTP method")
7979
testMocker.Config = testingConfig()
8080

8181
testMocker.Config.Endpoints[0].ResponseCode = 0

0 commit comments

Comments
 (0)