➖ Removed assert dependency from some tests
This commit is contained in:
parent
d5448c3766
commit
8655ce36bf
|
@ -4,7 +4,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/fasthttp/router"
|
"github.com/fasthttp/router"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
http "github.com/valyala/fasthttp"
|
http "github.com/valyala/fasthttp"
|
||||||
|
|
||||||
delivery "source.toby3d.me/website/indieauth/internal/health/delivery/http"
|
delivery "source.toby3d.me/website/indieauth/internal/health/delivery/http"
|
||||||
|
@ -20,7 +19,9 @@ func TestRequestHandler(t *testing.T) {
|
||||||
client, _, cleanup := httptest.New(t, r.Handler)
|
client, _, cleanup := httptest.New(t, r.Handler)
|
||||||
t.Cleanup(cleanup)
|
t.Cleanup(cleanup)
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "https://app.example.com/health", nil)
|
const requestURL = "https://app.example.com/health"
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodGet, requestURL, nil)
|
||||||
defer http.ReleaseRequest(req)
|
defer http.ReleaseRequest(req)
|
||||||
|
|
||||||
resp := http.AcquireResponse()
|
resp := http.AcquireResponse()
|
||||||
|
@ -30,6 +31,12 @@ func TestRequestHandler(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, http.StatusOK, resp.StatusCode())
|
if result := resp.StatusCode(); result != http.StatusOK {
|
||||||
assert.Equal(t, `{"ok": true}`, string(resp.Body()))
|
t.Errorf("GET %s = %d, want %d", requestURL, result, http.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
const expBody = `{"ok": true}`
|
||||||
|
if result := string(resp.Body()); result != expBody {
|
||||||
|
t.Errorf("GET %s = %s, want %s", requestURL, result, expBody)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/fasthttp/router"
|
"github.com/fasthttp/router"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
http "github.com/valyala/fasthttp"
|
http "github.com/valyala/fasthttp"
|
||||||
"golang.org/x/text/language"
|
"golang.org/x/text/language"
|
||||||
"golang.org/x/text/message"
|
"golang.org/x/text/message"
|
||||||
|
@ -80,5 +79,7 @@ func TestUpdate(t *testing.T) {
|
||||||
|
|
||||||
// TODO(toby3d): print the result as part of the debugging. Instead, you
|
// TODO(toby3d): print the result as part of the debugging. Instead, you
|
||||||
// need to send or save the token to the recipient for later use.
|
// need to send or save the token to the recipient for later use.
|
||||||
assert.NotNil(t, resp.Body())
|
if resp.Body() == nil {
|
||||||
|
t.Errorf("POST %s = nil, want something", requestURI)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/fasthttp/router"
|
"github.com/fasthttp/router"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
http "github.com/valyala/fasthttp"
|
http "github.com/valyala/fasthttp"
|
||||||
|
|
||||||
"source.toby3d.me/website/indieauth/internal/common"
|
"source.toby3d.me/website/indieauth/internal/common"
|
||||||
|
@ -44,7 +43,7 @@ func TestRedeem(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, token.AccessToken, result.AccessToken)
|
if result.String() != token.String() {
|
||||||
assert.Equal(t, token.Me.String(), result.Me.String())
|
t.Errorf("Redeem(%+v) = %s, want %s", ticket, result, token)
|
||||||
assert.Equal(t, token.Scope, result.Scope)
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
package http_test
|
package http_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/fasthttp/router"
|
"github.com/fasthttp/router"
|
||||||
json "github.com/goccy/go-json"
|
json "github.com/goccy/go-json"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
http "github.com/valyala/fasthttp"
|
http "github.com/valyala/fasthttp"
|
||||||
|
|
||||||
"source.toby3d.me/website/indieauth/internal/common"
|
"source.toby3d.me/website/indieauth/internal/common"
|
||||||
|
@ -53,7 +52,9 @@ func TestVerification(t *testing.T) {
|
||||||
client, _, cleanup := httptest.New(t, router.Handler)
|
client, _, cleanup := httptest.New(t, router.Handler)
|
||||||
t.Cleanup(cleanup)
|
t.Cleanup(cleanup)
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "https://app.example.com/token", nil)
|
const requestURL = "https://app.example.com/token"
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodGet, requestURL, nil)
|
||||||
defer http.ReleaseRequest(req)
|
defer http.ReleaseRequest(req)
|
||||||
req.Header.Set(http.HeaderAccept, common.MIMEApplicationJSON)
|
req.Header.Set(http.HeaderAccept, common.MIMEApplicationJSON)
|
||||||
token.SetAuthHeader(req)
|
token.SetAuthHeader(req)
|
||||||
|
@ -65,16 +66,22 @@ func TestVerification(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, http.StatusOK, resp.StatusCode())
|
if result := resp.StatusCode(); result != http.StatusOK {
|
||||||
|
t.Errorf("GET %s = %d, want %d", requestURL, result, http.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
result := new(delivery.TokenVerificationResponse)
|
result := new(delivery.TokenVerificationResponse)
|
||||||
if err := json.Unmarshal(resp.Body(), result); err != nil {
|
if err := json.Unmarshal(resp.Body(), result); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, token.ClientID.String(), result.ClientID.String())
|
token.AccessToken = ""
|
||||||
assert.Equal(t, token.Me.String(), result.Me.String())
|
|
||||||
assert.Equal(t, token.Scope.String(), result.Scope.String())
|
if result.ClientID.String() != token.ClientID.String() ||
|
||||||
|
result.Me.String() != token.Me.String() ||
|
||||||
|
result.Scope.String() != token.Scope.String() {
|
||||||
|
t.Errorf("GET %s = %+v, want %+v", requestURL, result, token)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRevocation(t *testing.T) {
|
func TestRevocation(t *testing.T) {
|
||||||
|
@ -102,7 +109,9 @@ func TestRevocation(t *testing.T) {
|
||||||
client, _, cleanup := httptest.New(t, router.Handler)
|
client, _, cleanup := httptest.New(t, router.Handler)
|
||||||
t.Cleanup(cleanup)
|
t.Cleanup(cleanup)
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "https://app.example.com/token", nil)
|
const requestURL = "https://app.example.com/token"
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodPost, requestURL, nil)
|
||||||
defer http.ReleaseRequest(req)
|
defer http.ReleaseRequest(req)
|
||||||
req.Header.Set(http.HeaderAccept, common.MIMEApplicationJSON)
|
req.Header.Set(http.HeaderAccept, common.MIMEApplicationJSON)
|
||||||
req.Header.SetContentType(common.MIMEApplicationForm)
|
req.Header.SetContentType(common.MIMEApplicationForm)
|
||||||
|
@ -116,13 +125,21 @@ func TestRevocation(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, http.StatusOK, resp.StatusCode())
|
if result := resp.StatusCode(); result != http.StatusOK {
|
||||||
assert.Equal(t, `{}`, strings.TrimSpace(string(resp.Body())))
|
t.Errorf("POST %s = %d, want %d", requestURL, result, http.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
expBody := []byte("{}") //nolint: ifshort
|
||||||
|
if result := bytes.TrimSpace(resp.Body()); !bytes.Equal(result, expBody) {
|
||||||
|
t.Errorf("POST %s = %s, want %s", requestURL, result, expBody)
|
||||||
|
}
|
||||||
|
|
||||||
result, err := tokens.Get(context.TODO(), accessToken.AccessToken)
|
result, err := tokens.Get(context.TODO(), accessToken.AccessToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, accessToken.AccessToken, result.AccessToken)
|
if result.String() != accessToken.String() {
|
||||||
|
t.Errorf("Get(%+v) = %s, want %s", accessToken.AccessToken, result, accessToken)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,5 +78,7 @@ func TestRevoke(t *testing.T) {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, accessToken.AccessToken, result.AccessToken)
|
if result.AccessToken != accessToken.AccessToken {
|
||||||
|
t.Errorf("Get(%s) = %s, want %s", accessToken.AccessToken, result.AccessToken, accessToken.AccessToken)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue