2024-03-22 15:08:24 +01:00
|
|
|
package web_test
|
2023-07-18 18:02:57 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"git.akyoto.dev/go/assert"
|
2024-03-22 15:08:24 +01:00
|
|
|
"git.akyoto.dev/go/web"
|
2023-07-18 18:02:57 +02:00
|
|
|
)
|
|
|
|
|
2024-03-26 22:46:16 +01:00
|
|
|
func TestBytes(t *testing.T) {
|
2024-03-22 15:08:24 +01:00
|
|
|
s := web.NewServer()
|
2023-07-18 18:02:57 +02:00
|
|
|
|
2024-03-22 15:08:24 +01:00
|
|
|
s.Get("/", func(ctx web.Context) error {
|
2023-07-18 18:02:57 +02:00
|
|
|
return ctx.Bytes([]byte("Hello"))
|
|
|
|
})
|
|
|
|
|
2024-03-26 22:46:16 +01:00
|
|
|
response := s.Test("GET", "/", nil)
|
|
|
|
assert.Equal(t, response.Status(), 200)
|
|
|
|
assert.DeepEqual(t, response.Body(), []byte("Hello"))
|
2024-03-13 20:18:01 +01:00
|
|
|
}
|
|
|
|
|
2024-03-26 22:46:16 +01:00
|
|
|
func TestString(t *testing.T) {
|
2024-03-22 15:08:24 +01:00
|
|
|
s := web.NewServer()
|
2023-07-19 12:31:33 +02:00
|
|
|
|
2024-03-26 22:46:16 +01:00
|
|
|
s.Get("/", func(ctx web.Context) error {
|
|
|
|
return ctx.String("Hello")
|
2023-07-19 12:31:33 +02:00
|
|
|
})
|
2024-03-12 22:31:45 +01:00
|
|
|
|
2024-03-26 22:46:16 +01:00
|
|
|
response := s.Test("GET", "/", nil)
|
|
|
|
assert.Equal(t, response.Status(), 200)
|
|
|
|
assert.DeepEqual(t, response.Body(), []byte("Hello"))
|
2024-03-12 22:31:45 +01:00
|
|
|
}
|