fiddling about
This commit is contained in:
8
testrig/config.go
Normal file
8
testrig/config.go
Normal file
@ -0,0 +1,8 @@
|
||||
package testrig
|
||||
|
||||
import "github.com/superseriousbusiness/gotosocial/internal/config"
|
||||
|
||||
// NewTestConfig returns a config initialized with test defaults
|
||||
func NewTestConfig() *config.Config {
|
||||
return config.TestDefault()
|
||||
}
|
||||
@ -1,6 +1,9 @@
|
||||
package testrig
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
||||
@ -23,65 +26,74 @@ var testModels []interface{} = []interface{}{
|
||||
&oauth.Client{},
|
||||
}
|
||||
|
||||
// NewTestDB returns a new initialized, empty database for testing
|
||||
func NewTestDB() db.DB {
|
||||
config := NewTestConfig()
|
||||
l := logrus.New()
|
||||
l.SetLevel(logrus.TraceLevel)
|
||||
testDB, err := db.New(context.Background(), config, l)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return testDB
|
||||
}
|
||||
|
||||
// StandardDBSetup populates a given db with all the necessary tables/models for perfoming tests.
|
||||
func StandardDBSetup(db db.DB) error {
|
||||
func StandardDBSetup(db db.DB) {
|
||||
for _, m := range testModels {
|
||||
if err := db.CreateTable(m); err != nil {
|
||||
return err
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range TestTokens() {
|
||||
for _, v := range NewTestTokens() {
|
||||
if err := db.Put(v); err != nil {
|
||||
return err
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range TestClients() {
|
||||
for _, v := range NewTestClients() {
|
||||
if err := db.Put(v); err != nil {
|
||||
return err
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range TestApplications() {
|
||||
for _, v := range NewTestApplications() {
|
||||
if err := db.Put(v); err != nil {
|
||||
return err
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range TestUsers() {
|
||||
for _, v := range NewTestUsers() {
|
||||
if err := db.Put(v); err != nil {
|
||||
return err
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range TestAccounts() {
|
||||
for _, v := range NewTestAccounts() {
|
||||
if err := db.Put(v); err != nil {
|
||||
return err
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range TestAttachments() {
|
||||
for _, v := range NewTestAttachments() {
|
||||
if err := db.Put(v); err != nil {
|
||||
return err
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range TestStatuses() {
|
||||
for _, v := range NewTestStatuses() {
|
||||
if err := db.Put(v); err != nil {
|
||||
return err
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// StandardDBTeardown drops all the standard testing tables/models from the database to ensure it's clean for the next test.
|
||||
func StandardDBTeardown(db db.DB) error {
|
||||
func StandardDBTeardown(db db.DB) {
|
||||
for _, m := range testModels {
|
||||
if err := db.DropTable(m); err != nil {
|
||||
return err
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
1
testrig/media/test-corrupted.jpg
Normal file
1
testrig/media/test-corrupted.jpg
Normal file
File diff suppressed because one or more lines are too long
BIN
testrig/media/test-jpeg-blurhash.jpg
Normal file
BIN
testrig/media/test-jpeg-blurhash.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.6 KiB |
BIN
testrig/media/test-jpeg-processed.jpg
Normal file
BIN
testrig/media/test-jpeg-processed.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 293 KiB |
BIN
testrig/media/test-jpeg-thumbnail.jpg
Normal file
BIN
testrig/media/test-jpeg-thumbnail.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.6 KiB |
BIN
testrig/media/test-jpeg.jpg
Normal file
BIN
testrig/media/test-jpeg.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 263 KiB |
BIN
testrig/media/test-with-exif.jpg
Normal file
BIN
testrig/media/test-with-exif.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 MiB |
BIN
testrig/media/test-without-exif.jpg
Normal file
BIN
testrig/media/test-without-exif.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 MiB |
@ -10,7 +10,7 @@ import (
|
||||
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
||||
)
|
||||
|
||||
func TestTokens() map[string]*oauth.Token {
|
||||
func NewTestTokens() map[string]*oauth.Token {
|
||||
tokens := map[string]*oauth.Token{
|
||||
"local_account_1": {
|
||||
ID: "64cf4214-33ab-4220-b5ca-4a6a12263b20",
|
||||
@ -26,7 +26,7 @@ func TestTokens() map[string]*oauth.Token {
|
||||
return tokens
|
||||
}
|
||||
|
||||
func TestClients() map[string]*oauth.Client {
|
||||
func NewTestClients() map[string]*oauth.Client {
|
||||
clients := map[string]*oauth.Client{
|
||||
"local_account_1": {
|
||||
ID: "73b48d42-029d-4487-80fc-329a5cf67869",
|
||||
@ -38,7 +38,7 @@ func TestClients() map[string]*oauth.Client {
|
||||
return clients
|
||||
}
|
||||
|
||||
func TestApplications() map[string]*gtsmodel.Application {
|
||||
func NewTestApplications() map[string]*gtsmodel.Application {
|
||||
apps := map[string]*gtsmodel.Application{
|
||||
"application_1": {
|
||||
ID: "f88697b8-ee3d-46c2-ac3f-dbb85566c3cc",
|
||||
@ -54,7 +54,7 @@ func TestApplications() map[string]*gtsmodel.Application {
|
||||
return apps
|
||||
}
|
||||
|
||||
func TestUsers() map[string]*gtsmodel.User {
|
||||
func NewTestUsers() map[string]*gtsmodel.User {
|
||||
users := map[string]*gtsmodel.User{
|
||||
"unconfirmed_account": {
|
||||
ID: "0f7b1d24-1e49-4ee0-bc7e-fd87b7289eea",
|
||||
@ -181,7 +181,7 @@ func TestUsers() map[string]*gtsmodel.User {
|
||||
return users
|
||||
}
|
||||
|
||||
func TestAccounts() map[string]*gtsmodel.Account {
|
||||
func NewTestAccounts() map[string]*gtsmodel.Account {
|
||||
accounts := map[string]*gtsmodel.Account{
|
||||
"unconfirmed_account": {
|
||||
ID: "59e197f5-87cd-4be8-ac7c-09082ccc4b4d",
|
||||
@ -440,7 +440,7 @@ func TestAccounts() map[string]*gtsmodel.Account {
|
||||
return accounts
|
||||
}
|
||||
|
||||
func TestAttachments() map[string]*gtsmodel.MediaAttachment {
|
||||
func NewTestAttachments() map[string]*gtsmodel.MediaAttachment {
|
||||
return map[string]*gtsmodel.MediaAttachment{
|
||||
// "admin_account_status_1": {
|
||||
|
||||
@ -448,7 +448,7 @@ func TestAttachments() map[string]*gtsmodel.MediaAttachment {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatuses() map[string]*gtsmodel.Status {
|
||||
func NewTestStatuses() map[string]*gtsmodel.Status {
|
||||
return map[string]*gtsmodel.Status{
|
||||
"admin_account_status_1": {
|
||||
ID: "502ccd6f-0edf-48d7-9016-2dfa4d3714cd",
|
||||
|
||||
24
testrig/storage.go
Normal file
24
testrig/storage.go
Normal file
@ -0,0 +1,24 @@
|
||||
package testrig
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/storage"
|
||||
)
|
||||
|
||||
// NewTestStorage returns a new in memory storage with the given config
|
||||
func NewTestStorage(c *config.Config, log *logrus.Logger) storage.Storage {
|
||||
s, err := storage.NewInMem(c, log)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func StandardStorageSetup(s storage.Storage) {
|
||||
|
||||
}
|
||||
|
||||
func StandardStorageTeardown(s storage.Storage) {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user