🧪 Added failing test
This commit is contained in:
parent
2746943991
commit
ae615df8c8
|
@ -2,11 +2,13 @@ package usecase_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"path"
|
"path"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"source.toby3d.me/toby3d/auth/internal/client"
|
||||||
repository "source.toby3d.me/toby3d/auth/internal/client/repository/memory"
|
repository "source.toby3d.me/toby3d/auth/internal/client/repository/memory"
|
||||||
"source.toby3d.me/toby3d/auth/internal/client/usecase"
|
"source.toby3d.me/toby3d/auth/internal/client/usecase"
|
||||||
"source.toby3d.me/toby3d/auth/internal/domain"
|
"source.toby3d.me/toby3d/auth/internal/domain"
|
||||||
|
@ -15,18 +17,48 @@ import (
|
||||||
func TestDiscovery(t *testing.T) {
|
func TestDiscovery(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
client := domain.TestClient(t)
|
|
||||||
|
|
||||||
store := new(sync.Map)
|
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)).
|
for _, client := range []*domain.Client{testClient, localhostClient} {
|
||||||
Discovery(context.Background(), client.ID)
|
store.Store(path.Join(repository.DefaultPathPrefix, client.ID.String()), client)
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(result, client) {
|
for _, tc := range []struct {
|
||||||
t.Errorf("Discovery(%s) = %+v, want %+v", client.ID, result, client)
|
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