🎨 Format testing utils

This commit is contained in:
Maxim Lebedev 2021-10-05 00:46:54 +05:00
parent 77004187d9
commit 8f7dec0fb0
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
7 changed files with 40 additions and 37 deletions

View File

@ -41,9 +41,8 @@ func NewHTTPClientRepository(c *http.Client) client.Repository {
func (repo *httpClientRepository) Get(ctx context.Context, id string) (*domain.Client, error) {
req := http.AcquireRequest()
defer http.ReleaseRequest(req)
req.Header.SetMethod(http.MethodGet)
req.SetRequestURI(id)
req.Header.SetMethod(http.MethodGet)
resp := http.AcquireResponse()
defer http.ReleaseResponse(resp)

View File

@ -14,34 +14,38 @@ import (
"source.toby3d.me/website/oauth/internal/util"
)
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>
`
func TestGet(t *testing.T) {
t.Parallel()
httpClient, _, cleanup := util.TestServe(t, func(ctx *http.RequestCtx) {
ctx.SuccessString(common.MIMETextHTML, `
<!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>
`)
ctx.Response.Header.Set(http.HeaderLink, `<http://app.example.com/redirect>; rel="redirect_uri">`)
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)
})
t.Cleanup(cleanup)
client := domain.TestClient(t)
c := domain.TestClient(t)
result, err := repository.NewHTTPClientRepository(httpClient).Get(context.TODO(), client.ID)
result, err := repository.NewHTTPClientRepository(client).Get(context.TODO(), c.ID)
require.NoError(t, err)
assert.Equal(t, client, result)
assert.Equal(t, c, result)
}

View File

@ -23,7 +23,7 @@ func TestMain(m *testing.M) {
"database.connection.filename": "./data/development.db",
"server.host": "127.0.0.1",
"server.port": 3000,
"url": "http://127.0.0.1:3000/",
"url": "https://127.0.0.1:3000/",
} {
v.Set(key, val)
}
@ -60,5 +60,5 @@ func TestPort(t *testing.T) {
func TestURL(t *testing.T) {
t.Parallel()
assert.Equal(t, "http://127.0.0.1:3000/", ucase.URL())
assert.Equal(t, "https://127.0.0.1:3000/", ucase.URL())
}

View File

@ -21,13 +21,13 @@ func TestClient(tb testing.TB) *Client {
tb.Helper()
return &Client{
ID: "http://app.example.com/",
ID: "https://app.example.com/",
Name: "Example App",
Logo: "http://app.example.com/logo.png",
URL: "http://app.example.com/",
Logo: "https://app.example.com/logo.png",
URL: "https://app.example.com/",
RedirectURI: []string{
"http://app.example.com/redirect",
"http://app.example.com/redirect",
"https://app.example.com/redirect",
"https://app.example.com/redirect",
},
}
}

View File

@ -14,8 +14,8 @@ func TestProfile(tb testing.TB) *Profile {
return &Profile{
Name: "Example User",
URL: "http://user.example.net/",
Photo: "http://user.example.net/photo.jpg",
URL: "https://user.example.net/",
Photo: "https://user.example.net/photo.jpg",
Email: "user@example.net",
}
}

View File

@ -27,8 +27,8 @@ func TestToken(tb testing.TB) *Token {
return &Token{
AccessToken: random.New().String(32),
ClientID: "http://app.example.com/",
Me: "http://user.example.net/",
ClientID: "https://app.example.com/",
Me: "https://user.example.net/",
Scopes: []string{"create", "update", "delete"},
Type: "Bearer",
}

View File

@ -33,7 +33,7 @@ func TestVerification(t *testing.T) {
req := http.AcquireRequest()
defer http.ReleaseRequest(req)
req.Header.SetMethod(http.MethodGet)
req.SetRequestURI("http://app.example.com/token")
req.SetRequestURI("https://app.example.com/token")
req.Header.Set(http.HeaderAccept, common.MIMEApplicationJSON)
req.Header.Set(http.HeaderAuthorization, "Bearer "+accessToken.AccessToken)
@ -67,7 +67,7 @@ func TestRevocation(t *testing.T) {
req := http.AcquireRequest()
defer http.ReleaseRequest(req)
req.Header.SetMethod(http.MethodPost)
req.SetRequestURI("http://app.example.com/token")
req.SetRequestURI("https://app.example.com/token")
req.Header.SetContentType(common.MIMEApplicationXWWWFormUrlencoded)
req.Header.Set(http.HeaderAccept, common.MIMEApplicationJSON)
req.PostArgs().Set("action", "revoke")