forked from ivpusic/httpcheck
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
1,199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package calc | ||
|
||
import ( | ||
"context" | ||
|
||
calcsvc "github.com/ikawaha/httpcheck/plugin/goa/calc/gen/calc" | ||
) | ||
|
||
// calc service example implementation. | ||
// The example methods log the requests and return zero values. | ||
type calcSvc struct{} | ||
|
||
// NewCalc returns the calc service implementation. | ||
func NewCalc() calcsvc.Service { | ||
return &calcSvc{} | ||
} | ||
|
||
// Multiply implements multiply. | ||
func (s *calcSvc) Multiply(_ context.Context, p *calcsvc.MultiplyPayload) (int, error) { | ||
return p.A * p.B, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package calc | ||
|
||
import ( | ||
"io" | ||
"net/http" | ||
"strconv" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/ikawaha/httpcheck" | ||
"github.com/ikawaha/httpcheck/plugin/goa" | ||
gen "github.com/ikawaha/httpcheck/plugin/goa/calc/gen/calc" | ||
"github.com/ikawaha/httpcheck/plugin/goa/calc/gen/http/calc/server" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestMounter(t *testing.T) { | ||
m := goa.NewMounter() | ||
m.Mount(goa.EndpointModular{ | ||
Builder: server.NewMultiplyHandler, | ||
Mounter: server.MountMultiplyHandler, | ||
Endpoint: gen.NewMultiplyEndpoint(NewCalc()), | ||
}) | ||
httpcheck.New(m).Test(t, "GET", "/multiply/3/5"). | ||
Check(). | ||
MustHasStatus(http.StatusOK). | ||
Cb(func(r *http.Response) { | ||
b, err := io.ReadAll(r.Body) | ||
require.NoError(t, err) | ||
i, err := strconv.Atoi(strings.TrimSpace(string(b))) | ||
assert.NoError(t, err, string(b)) | ||
assert.Equal(t, 3*5, i) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package design | ||
|
||
import ( | ||
. "goa.design/goa/v3/dsl" | ||
) | ||
|
||
var _ = Service("calc", func() { | ||
Description("The calc service performs operations on numbers") | ||
|
||
// Method describes a service method (endpoint) | ||
Method("multiply", func() { | ||
// Payload describes the method payload. | ||
// Here the payload is an object that consists of two fields. | ||
Payload(func() { | ||
// Attribute describes an object field | ||
Attribute("a", Int, "Left operand") | ||
Attribute("b", Int, "Right operand") | ||
Required("a", "b") | ||
}) | ||
|
||
// Result describes the method result. | ||
// Here the result is a simple integer value. | ||
Result(Int) | ||
|
||
// HTTP describes the HTTP transport mapping. | ||
HTTP(func() { | ||
// Requests to the service consist of HTTP GET requests. | ||
// The payload fields are encoded as path parameters. | ||
GET("/multiply/{a}/{b}") | ||
// Responses use a "200 OK" HTTP status. | ||
// The result is encoded in the response body. | ||
Response(StatusOK) | ||
}) | ||
}) | ||
|
||
// Serve the file gen/http/openapi3.json for requests sent to | ||
// /openapi.json. | ||
Files("/openapi.json", "openapi3.json") | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.