mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-25 13:16:40 +00:00
[bugfix] Fix loss of account info on export/import, add tests (#759)
* start adding additional tests * use random database address for in-memory sqlite * add more fields to account export
This commit is contained in:
parent
570fa7c359
commit
b96533ca8f
|
@ -31,6 +31,7 @@
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v4"
|
||||
"github.com/jackc/pgx/v4/stdlib"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/cache"
|
||||
|
@ -229,6 +230,15 @@ func sqliteConn(ctx context.Context) (*DBConn, error) {
|
|||
// Append our own SQLite preferences
|
||||
dbAddress = "file:" + dbAddress + "?cache=shared"
|
||||
|
||||
var inMem bool
|
||||
|
||||
if dbAddress == "file::memory:?cache=shared" {
|
||||
dbAddress = fmt.Sprintf("file:%s?mode=memory&cache=shared", uuid.NewString())
|
||||
log.Infof("using in-memory database address " + dbAddress)
|
||||
log.Warn("sqlite in-memory database should only be used for debugging")
|
||||
inMem = true
|
||||
}
|
||||
|
||||
// Open new DB instance
|
||||
sqldb, err := sql.Open("sqlite", dbAddress)
|
||||
if err != nil {
|
||||
|
@ -240,8 +250,7 @@ func sqliteConn(ctx context.Context) (*DBConn, error) {
|
|||
|
||||
tweakConnectionValues(sqldb)
|
||||
|
||||
if dbAddress == "file::memory:?cache=shared" {
|
||||
log.Warn("sqlite in-memory database should only be used for debugging")
|
||||
if inMem {
|
||||
// don't close connections on disconnect -- otherwise
|
||||
// the SQLite database will be deleted when there
|
||||
// are no active connections
|
||||
|
|
|
@ -38,12 +38,17 @@ type ImportMinimalTestSuite struct {
|
|||
func (suite *ImportMinimalTestSuite) TestImportMinimalOK() {
|
||||
ctx := context.Background()
|
||||
|
||||
testAccountBefore, err := suite.db.GetAccountByID(ctx, suite.testAccounts["local_account_1"].ID)
|
||||
if err != nil {
|
||||
suite.FailNow("couldn't get testAccountBefore")
|
||||
}
|
||||
|
||||
// use a temporary file path
|
||||
tempFilePath := fmt.Sprintf("%s/%s", suite.T().TempDir(), uuid.NewString())
|
||||
|
||||
// export to the tempFilePath
|
||||
exporter := trans.NewExporter(suite.db)
|
||||
err := exporter.ExportMinimal(ctx, tempFilePath)
|
||||
err = exporter.ExportMinimal(ctx, tempFilePath)
|
||||
suite.NoError(err)
|
||||
|
||||
// we should have some bytes in that file now
|
||||
|
@ -53,9 +58,7 @@ func (suite *ImportMinimalTestSuite) TestImportMinimalOK() {
|
|||
fmt.Println(string(b))
|
||||
|
||||
// create a new database with just the tables created, no entries
|
||||
testrig.StandardDBTeardown(suite.db)
|
||||
newDB := testrig.NewTestDB()
|
||||
testrig.CreateTestTables(newDB)
|
||||
|
||||
importer := trans.NewImporter(newDB)
|
||||
err = importer.Import(ctx, tempFilePath)
|
||||
|
@ -84,6 +87,41 @@ func (suite *ImportMinimalTestSuite) TestImportMinimalOK() {
|
|||
err = newDB.GetAll(ctx, &domainBlocks)
|
||||
suite.NoError(err)
|
||||
suite.NotEmpty(domainBlocks)
|
||||
|
||||
// compare test account before + after
|
||||
testAccountAfter, err := newDB.GetAccountByID(ctx, suite.testAccounts["local_account_1"].ID)
|
||||
if err != nil {
|
||||
suite.FailNow("couldn't get testAccountAfter")
|
||||
}
|
||||
|
||||
suite.Equal(testAccountBefore.ID, testAccountAfter.ID)
|
||||
suite.Equal(testAccountBefore.Username, testAccountAfter.Username)
|
||||
suite.Equal(testAccountBefore.Domain, testAccountAfter.Domain)
|
||||
suite.Equal(testAccountBefore.DisplayName, testAccountAfter.DisplayName)
|
||||
suite.Equal(testAccountBefore.Note, testAccountAfter.Note)
|
||||
suite.Equal(testAccountBefore.NoteRaw, testAccountAfter.NoteRaw)
|
||||
suite.Equal(testAccountBefore.Memorial, testAccountAfter.Memorial)
|
||||
suite.Equal(testAccountBefore.Bot, testAccountAfter.Bot)
|
||||
suite.Equal(testAccountBefore.Locked, testAccountAfter.Locked)
|
||||
suite.Equal(testAccountBefore.Reason, testAccountAfter.Reason)
|
||||
suite.Equal(testAccountBefore.Privacy, testAccountAfter.Privacy)
|
||||
suite.Equal(testAccountBefore.Sensitive, testAccountAfter.Sensitive)
|
||||
suite.Equal(testAccountBefore.Language, testAccountAfter.Language)
|
||||
suite.Equal(testAccountBefore.StatusFormat, testAccountAfter.StatusFormat)
|
||||
suite.Equal(testAccountBefore.URI, testAccountAfter.URI)
|
||||
suite.Equal(testAccountBefore.URL, testAccountAfter.URL)
|
||||
suite.Equal(testAccountBefore.InboxURI, testAccountAfter.InboxURI)
|
||||
suite.Equal(testAccountBefore.OutboxURI, testAccountAfter.OutboxURI)
|
||||
suite.Equal(testAccountBefore.FollowingURI, testAccountAfter.FollowingURI)
|
||||
suite.Equal(testAccountBefore.FollowersURI, testAccountAfter.FollowersURI)
|
||||
suite.Equal(testAccountBefore.FeaturedCollectionURI, testAccountAfter.FeaturedCollectionURI)
|
||||
suite.Equal(testAccountBefore.ActorType, testAccountAfter.ActorType)
|
||||
suite.Equal(testAccountBefore.PrivateKey, testAccountAfter.PrivateKey)
|
||||
suite.Equal(testAccountBefore.PublicKey, testAccountAfter.PublicKey)
|
||||
suite.Equal(testAccountBefore.PublicKeyURI, testAccountAfter.PublicKeyURI)
|
||||
suite.Equal(testAccountBefore.SuspendedAt, testAccountAfter.SuspendedAt)
|
||||
suite.Equal(testAccountBefore.HideCollections, testAccountAfter.HideCollections)
|
||||
suite.Equal(testAccountBefore.SuspensionOrigin, testAccountAfter.SuspensionOrigin)
|
||||
}
|
||||
|
||||
func TestImportMinimalTestSuite(t *testing.T) {
|
||||
|
|
|
@ -29,15 +29,24 @@ type Account struct {
|
|||
ID string `json:"id" bun:",nullzero"`
|
||||
CreatedAt *time.Time `json:"createdAt" bun:",nullzero"`
|
||||
Username string `json:"username" bun:",nullzero"`
|
||||
DisplayName string `json:"displayName,omitempty" bun:",nullzero"`
|
||||
Note string `json:"note,omitempty" bun:",nullzero"`
|
||||
Domain string `json:"domain,omitempty" bun:",nullzero"`
|
||||
HeaderRemoteURL string `json:"headerRemoteURL,omitempty" bun:",nullzero"`
|
||||
AvatarRemoteURL string `json:"avatarRemoteURL,omitempty" bun:",nullzero"`
|
||||
Locked *bool `json:"locked" bun:",nullzero,notnull,default:true"`
|
||||
DisplayName string `json:"displayName,omitempty" bun:",nullzero"`
|
||||
Note string `json:"note,omitempty" bun:",nullzero"`
|
||||
NoteRaw string `json:"noteRaw,omitempty" bun:",nullzero"`
|
||||
Memorial *bool `json:"memorial"`
|
||||
Bot *bool `json:"bot"`
|
||||
Reason string `json:"reason,omitempty" bun:",nullzero"`
|
||||
Locked *bool `json:"locked"`
|
||||
Discoverable *bool `json:"discoverable"`
|
||||
Privacy string `json:"privacy,omitempty" bun:",nullzero"`
|
||||
Sensitive *bool `json:"sensitive"`
|
||||
Language string `json:"language,omitempty" bun:",nullzero"`
|
||||
StatusFormat string `json:"statusFormat,omitempty" bun:",nullzero"`
|
||||
URI string `json:"uri" bun:",nullzero"`
|
||||
URL string `json:"url" bun:",nullzero"`
|
||||
LastWebfingeredAt *time.Time `json:"lastWebfingeredAt,omitempty" bun:",nullzero"`
|
||||
InboxURI string `json:"inboxURI" bun:",nullzero"`
|
||||
OutboxURI string `json:"outboxURI" bun:",nullzero"`
|
||||
FollowingURI string `json:"followingUri" bun:",nullzero"`
|
||||
|
@ -49,6 +58,9 @@ type Account struct {
|
|||
PublicKey *rsa.PublicKey `json:"-" mapstructure:"-"`
|
||||
PublicKeyString string `json:"publicKey,omitempty" mapstructure:"publicKey" bun:"-"`
|
||||
PublicKeyURI string `json:"publicKeyUri" bun:",nullzero"`
|
||||
SensitizedAt *time.Time `json:"sensitizedAt,omitempty" bun:",nullzero"`
|
||||
SilencedAt *time.Time `json:"silencedAt,omitempty" bun:",nullzero"`
|
||||
SuspendedAt *time.Time `json:"suspendedAt,omitempty" bun:",nullzero"`
|
||||
HideCollections *bool `json:"hideCollections"`
|
||||
SuspensionOrigin string `json:"suspensionOrigin,omitempty" bun:",nullzero"`
|
||||
}
|
||||
|
|
|
@ -21,17 +21,22 @@
|
|||
import (
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/testrig"
|
||||
)
|
||||
|
||||
type TransTestSuite struct {
|
||||
suite.Suite
|
||||
db db.DB
|
||||
testAccounts map[string]*gtsmodel.Account
|
||||
}
|
||||
|
||||
func (suite *TransTestSuite) SetupTest() {
|
||||
testrig.InitTestLog()
|
||||
testrig.InitTestConfig()
|
||||
testrig.InitTestLog()
|
||||
|
||||
suite.testAccounts = testrig.NewTestAccounts()
|
||||
|
||||
suite.db = testrig.NewTestDB()
|
||||
testrig.StandardDBSetup(suite.db, nil)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue