mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 13:29:41 +02:00
feat(libhttp): move into the Portainer repository EE-5475 (#10231)
This commit is contained in:
parent
090fa4aeb3
commit
8cc5e0796c
249 changed files with 1059 additions and 639 deletions
43
pkg/libhttp/request/payload_test.go
Normal file
43
pkg/libhttp/request/payload_test.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package request_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/portainer/portainer/pkg/libhttp/request"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type requestPayload struct {
|
||||
FirstName string `json:"first_name"`
|
||||
LastName string `json:"last_name"`
|
||||
}
|
||||
|
||||
func (p *requestPayload) Validate(r *http.Request) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func Test_GetPayload(t *testing.T) {
|
||||
|
||||
payload := requestPayload{
|
||||
FirstName: "John",
|
||||
LastName: "Doe",
|
||||
}
|
||||
|
||||
payloadJSON, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
r := httptest.NewRequest(http.MethodPost, "/", bytes.NewReader(payloadJSON))
|
||||
newPayload, err := request.GetPayload[requestPayload](r)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, payload, *newPayload)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue