🧪 Added failing test
This commit is contained in:
parent
2746943991
commit
ae615df8c8
|
@ -2,11 +2,13 @@ package usecase_test
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"path"
|
||||
"reflect"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"source.toby3d.me/toby3d/auth/internal/client"
|
||||
repository "source.toby3d.me/toby3d/auth/internal/client/repository/memory"
|
||||
"source.toby3d.me/toby3d/auth/internal/client/usecase"
|
||||
"source.toby3d.me/toby3d/auth/internal/domain"
|
||||
|
@ -15,18 +17,48 @@ import (
|
|||
func TestDiscovery(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
client := domain.TestClient(t)
|
||||
|
||||
store := new(sync.Map)
|
||||
store.Store(path.Join(repository.DefaultPathPrefix, client.ID.String()), client)
|
||||
testClient, localhostClient := domain.TestClient(t), domain.TestClient(t)
|
||||
localhostClient.ID, _ = domain.ParseClientID("http://localhost.toby3d.me/")
|
||||
|
||||
result, err := usecase.NewClientUseCase(repository.NewMemoryClientRepository(store)).
|
||||
Discovery(context.Background(), client.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
for _, client := range []*domain.Client{testClient, localhostClient} {
|
||||
store.Store(path.Join(repository.DefaultPathPrefix, client.ID.String()), client)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(result, client) {
|
||||
t.Errorf("Discovery(%s) = %+v, want %+v", client.ID, result, client)
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
in *domain.Client
|
||||
out *domain.Client
|
||||
expError error
|
||||
}{{
|
||||
name: "default",
|
||||
in: testClient,
|
||||
out: testClient,
|
||||
}, {
|
||||
name: "localhost",
|
||||
in: localhostClient,
|
||||
expError: client.ErrNotExist,
|
||||
}} {
|
||||
tc := tc
|
||||
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
result, err := usecase.NewClientUseCase(repository.NewMemoryClientRepository(store)).
|
||||
Discovery(context.Background(), tc.in.ID)
|
||||
if tc.expError != nil && !errors.Is(err, tc.expError) {
|
||||
t.Errorf("Discovery(%s) = %+v, want %+v", tc.in.ID, err, tc.expError)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if tc.expError == nil && err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(result, tc.out) {
|
||||
t.Errorf("Discovery(%s) = %+v, want %+v", tc.in.ID, result, tc.out)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue