diff options
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/db/bundb/bundb.go | 13 | ||||
| -rw-r--r-- | internal/trans/import_test.go | 44 | ||||
| -rw-r--r-- | internal/trans/model/account.go | 18 | ||||
| -rw-r--r-- | internal/trans/trans_test.go | 9 | 
4 files changed, 74 insertions, 10 deletions
diff --git a/internal/db/bundb/bundb.go b/internal/db/bundb/bundb.go index 191350d06..ca123543a 100644 --- a/internal/db/bundb/bundb.go +++ b/internal/db/bundb/bundb.go @@ -31,6 +31,7 @@ import (  	"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 diff --git a/internal/trans/import_test.go b/internal/trans/import_test.go index a29535d85..b857abe32 100644 --- a/internal/trans/import_test.go +++ b/internal/trans/import_test.go @@ -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) { diff --git a/internal/trans/model/account.go b/internal/trans/model/account.go index 1687d7676..e8abaf86f 100644 --- a/internal/trans/model/account.go +++ b/internal/trans/model/account.go @@ -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"`  } diff --git a/internal/trans/trans_test.go b/internal/trans/trans_test.go index f7b85af1b..4eedf5703 100644 --- a/internal/trans/trans_test.go +++ b/internal/trans/trans_test.go @@ -21,17 +21,22 @@ package trans_test  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 +	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)  }  | 
