mirror of https://gitlab.com/ngerakines/tavern.git
104 lines
3.0 KiB
Go
104 lines
3.0 KiB
Go
package job
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/gin-contrib/sessions"
|
|
"github.com/gofrs/uuid"
|
|
"github.com/stretchr/testify/assert"
|
|
"go.uber.org/zap"
|
|
|
|
"github.com/ngerakines/tavern/storage"
|
|
)
|
|
|
|
type mockStorage struct {
|
|
GetActorFunc func(context.Context, string) (storage.Actor, error)
|
|
CreateActorFunc func(context.Context, uuid.UUID, uuid.UUID, string, string, string, string) error
|
|
}
|
|
|
|
func (m mockStorage) RowCount(ctx context.Context, query string, args ...interface{}) (int, error) {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (m mockStorage) AuthenticateUser(ctx context.Context, email string, password []byte) (uuid.UUID, error) {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (m mockStorage) CreateUser(ctx context.Context, userID uuid.UUID, email, locale, name, displayName, about, publicKey, privateKey string, password []byte) error {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (m mockStorage) GetUser(ctx context.Context, userID uuid.UUID) (*storage.User, error) {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (m mockStorage) GetUserByName(ctx context.Context, name string) (*storage.User, error) {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (m mockStorage) GetUserBySession(ctx context.Context, session sessions.Session) (*storage.User, error) {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (m mockStorage) UpdateUserLastAuth(ctx context.Context, userID uuid.UUID) error {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (m mockStorage) GetUserFollowers(ctx context.Context, userID uuid.UUID, limit, offset int) ([]string, error) {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (m mockStorage) GetUserFollowing(ctx context.Context, userID uuid.UUID, limit, offset int) ([]string, error) {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (m mockStorage) RecordActivity(ctx context.Context, activityID uuid.UUID, payload string) error {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (m mockStorage) GetActor(ctx context.Context, id string) (storage.Actor, error) {
|
|
if m.GetActorFunc != nil {
|
|
return m.GetActorFunc(ctx, id)
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
func (m mockStorage) CreateActor(a context.Context, b uuid.UUID, c uuid.UUID, d string, e string, f string, g string) error {
|
|
if m.CreateActorFunc != nil {
|
|
return m.CreateActorFunc(a, b, c, d, e, f, g)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
var _ storage.Storage = mockStorage{}
|
|
|
|
func TestWebfinger_Run(t *testing.T) {
|
|
// if skip, _ := strconv.ParseBool(os.Getenv("TEST_INTEGRATION")); !skip {
|
|
// t.Skip("skipping integration test")
|
|
// return
|
|
// }
|
|
|
|
logger, _ := zap.NewDevelopment()
|
|
|
|
q := storage.NewStringQueue()
|
|
// assert.NoError(t, q.Add("https://mastodon.social/users/ngerakines"))
|
|
// assert.NoError(t, q.Add("@ngerakines@mastodon.social"))
|
|
assert.NoError(t, q.Add("ngerakines@mastodon.social"))
|
|
|
|
j := &webfinger{
|
|
logger: logger,
|
|
queue: q,
|
|
storage: mockStorage{
|
|
CreateActorFunc: func(ctx context.Context, u uuid.UUID, u2 uuid.UUID, actorID string, s2 string, keyID string, s4 string) error {
|
|
assert.Equal(t, "https://mastodon.social/@ngerakines", actorID)
|
|
assert.Equal(t, "https://mastodon.social/users/ngerakines#main-key", keyID)
|
|
return nil
|
|
},
|
|
},
|
|
httpClient: DefaultHTTPClient(),
|
|
}
|
|
assert.NoError(t, j.work())
|
|
|
|
}
|