biiiiig refactor

This commit is contained in:
tsmethurst 2021-05-04 17:50:00 +02:00
commit 1ec22fe52c
151 changed files with 3231 additions and 4556 deletions

View file

@ -30,16 +30,15 @@ import (
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/action"
"github.com/superseriousbusiness/gotosocial/internal/apimodule"
"github.com/superseriousbusiness/gotosocial/internal/apimodule/account"
"github.com/superseriousbusiness/gotosocial/internal/apimodule/admin"
"github.com/superseriousbusiness/gotosocial/internal/apimodule/app"
"github.com/superseriousbusiness/gotosocial/internal/apimodule/auth"
"github.com/superseriousbusiness/gotosocial/internal/apimodule/fileserver"
mediaModule "github.com/superseriousbusiness/gotosocial/internal/apimodule/media"
"github.com/superseriousbusiness/gotosocial/internal/apimodule/security"
"github.com/superseriousbusiness/gotosocial/internal/apimodule/status"
"github.com/superseriousbusiness/gotosocial/internal/cache"
"github.com/superseriousbusiness/gotosocial/internal/api"
"github.com/superseriousbusiness/gotosocial/internal/api/client/account"
"github.com/superseriousbusiness/gotosocial/internal/api/client/admin"
"github.com/superseriousbusiness/gotosocial/internal/api/client/app"
"github.com/superseriousbusiness/gotosocial/internal/api/client/auth"
"github.com/superseriousbusiness/gotosocial/internal/api/client/fileserver"
mediaModule "github.com/superseriousbusiness/gotosocial/internal/api/client/media"
"github.com/superseriousbusiness/gotosocial/internal/api/client/status"
"github.com/superseriousbusiness/gotosocial/internal/api/security"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/federation"
"github.com/superseriousbusiness/gotosocial/internal/gotosocial"
@ -51,11 +50,9 @@ var Run action.GTSAction = func(ctx context.Context, _ *config.Config, log *logr
dbService := NewTestDB()
router := NewTestRouter()
storageBackend := NewTestStorage()
mediaHandler := NewTestMediaHandler(dbService, storageBackend)
oauthServer := NewTestOauthServer(dbService)
distributor := NewTestDistributor()
if err := distributor.Start(); err != nil {
return fmt.Errorf("error starting distributor: %s", err)
processor := NewTestProcessor(dbService, storageBackend)
if err := processor.Start(); err != nil {
return fmt.Errorf("error starting processor: %s", err)
}
typeConverter := NewTestTypeConverter(dbService)
transportController := NewTestTransportController(NewMockHTTPClient(func(req *http.Request) (*http.Response, error) {
@ -65,22 +62,22 @@ var Run action.GTSAction = func(ctx context.Context, _ *config.Config, log *logr
Body: r,
}, nil
}))
federator := federation.NewFederator(dbService, transportController, c, log, distributor, typeConverter)
federator := federation.NewFederator(dbService, transportController, c, log, processor, typeConverter)
StandardDBSetup(dbService)
StandardStorageSetup(storageBackend, "./testrig/media")
// build client api modules
authModule := auth.New(oauthServer, dbService, log)
accountModule := account.New(c, dbService, oauthServer, mediaHandler, typeConverter, log)
appsModule := app.New(oauthServer, dbService, typeConverter, log)
mm := mediaModule.New(dbService, mediaHandler, typeConverter, c, log)
fileServerModule := fileserver.New(c, dbService, storageBackend, log)
adminModule := admin.New(c, dbService, mediaHandler, typeConverter, log)
statusModule := status.New(c, dbService, mediaHandler, typeConverter, distributor, log)
authModule := auth.New(c, processor, log)
accountModule := account.New(c, processor, log)
appsModule := app.New(c, processor, log)
mm := mediaModule.New(c, processor, log)
fileServerModule := fileserver.New(c, processor, log)
adminModule := admin.New(c, processor, log)
statusModule := status.New(c, processor, log)
securityModule := security.New(c, log)
apiModules := []apimodule.ClientAPIModule{
apis := []api.ClientModule{
// modules with middleware go first
securityModule,
authModule,
@ -94,20 +91,13 @@ var Run action.GTSAction = func(ctx context.Context, _ *config.Config, log *logr
statusModule,
}
for _, m := range apiModules {
for _, m := range apis {
if err := m.Route(router); err != nil {
return fmt.Errorf("routing error: %s", err)
}
if err := m.CreateTables(dbService); err != nil {
return fmt.Errorf("table creation error: %s", err)
}
}
// if err := dbService.CreateInstanceAccount(); err != nil {
// return fmt.Errorf("error creating instance account: %s", err)
// }
gts, err := gotosocial.New(dbService, &cache.MockCache{}, router, federator, c)
gts, err := gotosocial.New(dbService, router, federator, c)
if err != nil {
return fmt.Errorf("error creating gotosocial service: %s", err)
}

View file

@ -23,7 +23,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
)
@ -54,7 +54,7 @@ func NewTestDB() db.DB {
config := NewTestConfig()
l := logrus.New()
l.SetLevel(logrus.TraceLevel)
testDB, err := db.New(context.Background(), config, l)
testDB, err := db.NewPostgresService(context.Background(), config, l)
if err != nil {
panic(err)
}

BIN
testrig/media/test-jpeg.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 KiB

View file

@ -18,9 +18,13 @@
package testrig
import "github.com/superseriousbusiness/gotosocial/internal/distributor"
import (
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/message"
"github.com/superseriousbusiness/gotosocial/internal/storage"
)
// NewTestDistributor returns a Distributor suitable for testing purposes
func NewTestDistributor() distributor.Distributor {
return distributor.New(NewTestLog())
// NewTestProcessor returns a Processor suitable for testing purposes
func NewTestProcessor(db db.DB, storage storage.Storage) message.Processor {
return message.NewProcessor(NewTestConfig(), NewTestTypeConverter(db), NewTestOauthServer(db), NewTestMediaHandler(db, storage), db, NewTestLog())
}

View file

@ -34,7 +34,7 @@ import (
"github.com/go-fed/activity/pub"
"github.com/go-fed/activity/streams"
"github.com/go-fed/activity/streams/vocab"
"github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
)