➖ Removed assert/require from some tests
This commit is contained in:
parent
e0948d88a4
commit
39f4bfd714
1
go.mod
1
go.mod
|
@ -14,7 +14,6 @@ require (
|
|||
github.com/hashicorp/go-retryablehttp v0.7.0 // indirect
|
||||
github.com/jmoiron/sqlx v1.3.4
|
||||
github.com/klauspost/compress v1.14.2 // indirect
|
||||
github.com/lestrrat-go/iter v1.0.1 // indirect
|
||||
github.com/lestrrat-go/jwx v1.2.18
|
||||
github.com/mattn/go-mastodon v0.0.4
|
||||
github.com/spf13/afero v1.8.0 // indirect
|
||||
|
|
|
@ -2,14 +2,13 @@ package http_test
|
|||
|
||||
import (
|
||||
"path"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/fasthttp/router"
|
||||
"github.com/fasthttp/session/v2"
|
||||
"github.com/fasthttp/session/v2/providers/memory"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
http "github.com/valyala/fasthttp"
|
||||
"golang.org/x/text/language"
|
||||
"golang.org/x/text/message"
|
||||
|
@ -25,14 +24,19 @@ import (
|
|||
userrepo "source.toby3d.me/website/indieauth/internal/user/repository/memory"
|
||||
)
|
||||
|
||||
//nolint: funlen
|
||||
func TestRender(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
provider, err := memory.New(memory.Config{})
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
s := session.New(session.NewDefaultConfig())
|
||||
require.NoError(t, s.SetProvider(provider))
|
||||
if err = s.SetProvider(provider); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
me := domain.TestMe(t, "https://user.example.net")
|
||||
client := domain.TestClient(t)
|
||||
|
@ -80,8 +84,16 @@ func TestRender(t *testing.T) {
|
|||
resp := http.AcquireResponse()
|
||||
defer http.ReleaseResponse(resp)
|
||||
|
||||
require.NoError(t, httpClient.Do(req, resp))
|
||||
if err := httpClient.Do(req, resp); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, http.StatusOK, resp.StatusCode())
|
||||
assert.Contains(t, string(resp.Body()), `Authorize application`)
|
||||
if resp.StatusCode() != http.StatusOK {
|
||||
t.Errorf("GET %s = %d, want %d", uri.String(), resp.StatusCode(), http.StatusOK)
|
||||
}
|
||||
|
||||
const expResult = `Authorize application`
|
||||
if result := string(resp.Body()); !strings.Contains(result, expResult) {
|
||||
t.Errorf("GET %s = %s, want %s", uri.String(), result, expResult)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,6 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/fasthttp/router"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
http "github.com/valyala/fasthttp"
|
||||
"golang.org/x/text/language"
|
||||
"golang.org/x/text/message"
|
||||
|
@ -37,12 +35,19 @@ func TestRead(t *testing.T) {
|
|||
client, _, cleanup := httptest.New(t, router.Handler)
|
||||
t.Cleanup(cleanup)
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, "https://app.example.com/", nil)
|
||||
const requestURI string = "https://app.example.com/"
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, requestURI, nil)
|
||||
defer http.ReleaseRequest(req)
|
||||
|
||||
resp := http.AcquireResponse()
|
||||
defer http.ReleaseResponse(resp)
|
||||
|
||||
require.NoError(t, client.Do(req, resp))
|
||||
assert.Equal(t, http.StatusOK, resp.StatusCode())
|
||||
if err := client.Do(req, resp); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if resp.StatusCode() != http.StatusOK {
|
||||
t.Errorf("GET %s = %d, want %d", requestURI, resp.StatusCode(), http.StatusOK)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,12 +3,10 @@ package memory_test
|
|||
import (
|
||||
"context"
|
||||
"path"
|
||||
"reflect"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
repository "source.toby3d.me/website/indieauth/internal/client/repository/memory"
|
||||
"source.toby3d.me/website/indieauth/internal/domain"
|
||||
)
|
||||
|
@ -21,7 +19,13 @@ func TestGet(t *testing.T) {
|
|||
store := new(sync.Map)
|
||||
store.Store(path.Join(repository.DefaultPathPrefix, client.ID.String()), client)
|
||||
|
||||
result, err := repository.NewMemoryClientRepository(store).Get(context.TODO(), client.ID)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, client, result)
|
||||
result, err := repository.NewMemoryClientRepository(store).
|
||||
Get(context.TODO(), client.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(result, client) {
|
||||
t.Errorf("Get(%s) = %+v, want %+v", client.ID, result, client)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,12 +3,10 @@ package usecase_test
|
|||
import (
|
||||
"context"
|
||||
"path"
|
||||
"reflect"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
repository "source.toby3d.me/website/indieauth/internal/client/repository/memory"
|
||||
"source.toby3d.me/website/indieauth/internal/client/usecase"
|
||||
"source.toby3d.me/website/indieauth/internal/domain"
|
||||
|
@ -24,6 +22,11 @@ func TestDiscovery(t *testing.T) {
|
|||
|
||||
result, err := usecase.NewClientUseCase(repository.NewMemoryClientRepository(store)).
|
||||
Discovery(context.TODO(), client.ID)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, client, result)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(result, client) {
|
||||
t.Errorf("Discovery(%s) = %+v, want %+v", client.ID, result, client)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,6 @@ import (
|
|||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
bolt "go.etcd.io/bbolt"
|
||||
)
|
||||
|
||||
|
@ -15,16 +13,23 @@ func New(tb testing.TB) (*bolt.DB, func()) {
|
|||
tb.Helper()
|
||||
|
||||
f, err := os.CreateTemp(os.TempDir(), "bbolt_*.db")
|
||||
require.NoError(tb, err)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
}
|
||||
|
||||
filePath := f.Name()
|
||||
assert.NoError(tb, f.Close())
|
||||
|
||||
if err := f.Close(); err != nil {
|
||||
tb.Fatal(err)
|
||||
}
|
||||
|
||||
db, err := bolt.Open(filePath, os.ModePerm, nil)
|
||||
require.NoError(tb, err)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
}
|
||||
|
||||
return db, func() {
|
||||
db.Close()
|
||||
os.Remove(filePath)
|
||||
_ = db.Close()
|
||||
_ = os.Remove(filePath)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,12 +3,10 @@ package memory_test
|
|||
import (
|
||||
"context"
|
||||
"path"
|
||||
"reflect"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"source.toby3d.me/website/indieauth/internal/domain"
|
||||
repository "source.toby3d.me/website/indieauth/internal/user/repository/memory"
|
||||
)
|
||||
|
@ -22,6 +20,11 @@ func TestGet(t *testing.T) {
|
|||
store.Store(path.Join(repository.DefaultPathPrefix, user.Me.String()), user)
|
||||
|
||||
result, err := repository.NewMemoryUserRepository(store).Get(context.TODO(), user.Me)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, user, result)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(result, user) {
|
||||
t.Errorf("Get(%s) = %+v, want %+v", user.Me, result, user)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,11 +3,10 @@ package usecase_test
|
|||
import (
|
||||
"context"
|
||||
"path"
|
||||
"reflect"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"source.toby3d.me/website/indieauth/internal/domain"
|
||||
repository "source.toby3d.me/website/indieauth/internal/user/repository/memory"
|
||||
ucase "source.toby3d.me/website/indieauth/internal/user/usecase"
|
||||
|
@ -24,6 +23,11 @@ func TestFetch(t *testing.T) {
|
|||
|
||||
result, err := ucase.NewUserUseCase(repository.NewMemoryUserRepository(store)).
|
||||
Fetch(context.TODO(), me)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, user, result)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(result, user) {
|
||||
t.Errorf("Fetch(%s) = %+v, want %+v", me, result, user)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue