You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.0 KiB
54 lines
1.0 KiB
package nwweb
|
|
|
|
import (
|
|
"fmt"
|
|
"git.nwestland.com/tools/nwjson"
|
|
"io"
|
|
"net/http"
|
|
"testing"
|
|
)
|
|
|
|
func Test(t *testing.T) {
|
|
req, err := http.NewRequest(http.MethodGet, "https://www.postman-echo.com/get", nil)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
|
|
resp, err := http.DefaultClient.Do(req)
|
|
data, _ := io.ReadAll(resp.Body)
|
|
resp.Body.Close()
|
|
|
|
fmt.Println(len(data))
|
|
}
|
|
|
|
func TestNew(t *testing.T) {
|
|
req := NewRequest(POST, "https://www.postman-echo.com/post")
|
|
req.QueryParameters.Set("query", "test")
|
|
req.Body.MarshalJson(nwjson.Object{"Username": "johndoe"})
|
|
|
|
resp := DefaultClient.Do(req)
|
|
fmt.Println(resp.Body.Object().ToPrettyString())
|
|
}
|
|
|
|
func TestServer(t *testing.T) {
|
|
server := NewServer("localhost", 8080)
|
|
server.RegisterController(TestController{})
|
|
server.Start()
|
|
}
|
|
|
|
type TestController struct{}
|
|
|
|
func (e TestController) GetRoutes() []Route {
|
|
return []Route{
|
|
{
|
|
Pattern: "/",
|
|
Handler: e.Test,
|
|
Method: GET,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (e TestController) Test(response *Response, request *Request) {
|
|
response.Body.WriteString("Hi there")
|
|
}
|