2021-09-23 23:01:28 +00:00
|
|
|
package http_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2021-09-25 11:00:19 +00:00
|
|
|
http "github.com/valyala/fasthttp"
|
2021-09-29 20:35:39 +00:00
|
|
|
|
2021-09-25 11:00:19 +00:00
|
|
|
repository "source.toby3d.me/website/oauth/internal/client/repository/http"
|
2021-09-23 23:01:28 +00:00
|
|
|
"source.toby3d.me/website/oauth/internal/common"
|
2021-09-29 20:35:39 +00:00
|
|
|
"source.toby3d.me/website/oauth/internal/domain"
|
2021-09-30 22:24:40 +00:00
|
|
|
"source.toby3d.me/website/oauth/internal/util"
|
2021-09-23 23:01:28 +00:00
|
|
|
)
|
|
|
|
|
2021-10-04 19:46:54 +00:00
|
|
|
const testBody string = `
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<title>Example App</title>
|
|
|
|
<link rel="redirect_uri" href="/redirect">
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div class="h-app">
|
|
|
|
<img src="/logo.png" class="u-logo">
|
|
|
|
<a href="/" class="u-url p-name">Example App</a>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
`
|
|
|
|
|
2021-09-23 23:01:28 +00:00
|
|
|
func TestGet(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2021-10-04 19:46:54 +00:00
|
|
|
client, _, cleanup := util.TestServe(t, func(ctx *http.RequestCtx) {
|
|
|
|
ctx.Response.Header.Set(http.HeaderLink, `<https://app.example.com/redirect>; rel="redirect_uri">`)
|
|
|
|
ctx.SetStatusCode(http.StatusOK)
|
|
|
|
ctx.SetContentType(common.MIMETextHTML)
|
|
|
|
ctx.SetBodyString(testBody)
|
2021-09-23 23:01:28 +00:00
|
|
|
})
|
2021-09-30 22:24:40 +00:00
|
|
|
t.Cleanup(cleanup)
|
2021-09-23 23:01:28 +00:00
|
|
|
|
2021-10-04 19:46:54 +00:00
|
|
|
c := domain.TestClient(t)
|
2021-09-25 11:00:19 +00:00
|
|
|
|
2021-10-04 19:46:54 +00:00
|
|
|
result, err := repository.NewHTTPClientRepository(client).Get(context.TODO(), c.ID)
|
2021-09-23 23:01:28 +00:00
|
|
|
require.NoError(t, err)
|
2021-10-04 19:46:54 +00:00
|
|
|
assert.Equal(t, c, result)
|
2021-09-23 23:01:28 +00:00
|
|
|
}
|