1
0
Fork 0
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:
andres-portainer 2023-09-01 19:27:02 -03:00 committed by GitHub
parent 090fa4aeb3
commit 8cc5e0796c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
249 changed files with 1059 additions and 639 deletions

View 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)
}