gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

import_test.go (5055B)


      1 // GoToSocial
      2 // Copyright (C) GoToSocial Authors admin@gotosocial.org
      3 // SPDX-License-Identifier: AGPL-3.0-or-later
      4 //
      5 // This program is free software: you can redistribute it and/or modify
      6 // it under the terms of the GNU Affero General Public License as published by
      7 // the Free Software Foundation, either version 3 of the License, or
      8 // (at your option) any later version.
      9 //
     10 // This program is distributed in the hope that it will be useful,
     11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 // GNU Affero General Public License for more details.
     14 //
     15 // You should have received a copy of the GNU Affero General Public License
     16 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 
     18 package trans_test
     19 
     20 import (
     21 	"context"
     22 	"fmt"
     23 	"os"
     24 	"testing"
     25 
     26 	"github.com/google/uuid"
     27 	"github.com/stretchr/testify/suite"
     28 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
     29 	"github.com/superseriousbusiness/gotosocial/internal/state"
     30 	"github.com/superseriousbusiness/gotosocial/internal/trans"
     31 	"github.com/superseriousbusiness/gotosocial/testrig"
     32 )
     33 
     34 type ImportMinimalTestSuite struct {
     35 	TransTestSuite
     36 }
     37 
     38 func (suite *ImportMinimalTestSuite) TestImportMinimalOK() {
     39 	ctx := context.Background()
     40 
     41 	testAccountBefore, err := suite.db.GetAccountByID(ctx, suite.testAccounts["local_account_1"].ID)
     42 	if err != nil {
     43 		suite.FailNow("couldn't get testAccountBefore")
     44 	}
     45 
     46 	// use a temporary file path
     47 	tempFilePath := fmt.Sprintf("%s/%s", suite.T().TempDir(), uuid.NewString())
     48 
     49 	// export to the tempFilePath
     50 	exporter := trans.NewExporter(suite.db)
     51 	err = exporter.ExportMinimal(ctx, tempFilePath)
     52 	suite.NoError(err)
     53 
     54 	// we should have some bytes in that file now
     55 	b, err := os.ReadFile(tempFilePath)
     56 	suite.NoError(err)
     57 	suite.NotEmpty(b)
     58 	fmt.Println(string(b))
     59 
     60 	var state state.State
     61 	state.Caches.Init()
     62 
     63 	// create a new database with just the tables created, no entries
     64 	newDB := testrig.NewTestDB(&state)
     65 
     66 	importer := trans.NewImporter(newDB)
     67 	err = importer.Import(ctx, tempFilePath)
     68 	suite.NoError(err)
     69 
     70 	// we should have some accounts in the database
     71 	accounts := []*gtsmodel.Account{}
     72 	err = newDB.GetAll(ctx, &accounts)
     73 	suite.NoError(err)
     74 	suite.NotEmpty(accounts)
     75 
     76 	// we should have some blocks in the database
     77 	blocks := []*gtsmodel.Block{}
     78 	err = newDB.GetAll(ctx, &blocks)
     79 	suite.NoError(err)
     80 	suite.NotEmpty(blocks)
     81 
     82 	// we should have some follows in the database
     83 	follows := []*gtsmodel.Follow{}
     84 	err = newDB.GetAll(ctx, &follows)
     85 	suite.NoError(err)
     86 	suite.NotEmpty(follows)
     87 
     88 	// we should have some domain blocks in the database
     89 	domainBlocks := []*gtsmodel.DomainBlock{}
     90 	err = newDB.GetAll(ctx, &domainBlocks)
     91 	suite.NoError(err)
     92 	suite.NotEmpty(domainBlocks)
     93 
     94 	// compare test account before + after
     95 	testAccountAfter, err := newDB.GetAccountByID(ctx, suite.testAccounts["local_account_1"].ID)
     96 	if err != nil {
     97 		suite.FailNow("couldn't get testAccountAfter")
     98 	}
     99 
    100 	suite.Equal(testAccountBefore.ID, testAccountAfter.ID)
    101 	suite.Equal(testAccountBefore.Username, testAccountAfter.Username)
    102 	suite.Equal(testAccountBefore.Domain, testAccountAfter.Domain)
    103 	suite.Equal(testAccountBefore.DisplayName, testAccountAfter.DisplayName)
    104 	suite.Equal(testAccountBefore.Note, testAccountAfter.Note)
    105 	suite.Equal(testAccountBefore.NoteRaw, testAccountAfter.NoteRaw)
    106 	suite.Equal(testAccountBefore.Memorial, testAccountAfter.Memorial)
    107 	suite.Equal(testAccountBefore.Bot, testAccountAfter.Bot)
    108 	suite.Equal(testAccountBefore.Locked, testAccountAfter.Locked)
    109 	suite.Equal(testAccountBefore.Reason, testAccountAfter.Reason)
    110 	suite.Equal(testAccountBefore.Privacy, testAccountAfter.Privacy)
    111 	suite.Equal(testAccountBefore.Sensitive, testAccountAfter.Sensitive)
    112 	suite.Equal(testAccountBefore.Language, testAccountAfter.Language)
    113 	suite.Equal(testAccountBefore.StatusContentType, testAccountAfter.StatusContentType)
    114 	suite.Equal(testAccountBefore.URI, testAccountAfter.URI)
    115 	suite.Equal(testAccountBefore.URL, testAccountAfter.URL)
    116 	suite.Equal(testAccountBefore.InboxURI, testAccountAfter.InboxURI)
    117 	suite.Equal(testAccountBefore.OutboxURI, testAccountAfter.OutboxURI)
    118 	suite.Equal(testAccountBefore.FollowingURI, testAccountAfter.FollowingURI)
    119 	suite.Equal(testAccountBefore.FollowersURI, testAccountAfter.FollowersURI)
    120 	suite.Equal(testAccountBefore.FeaturedCollectionURI, testAccountAfter.FeaturedCollectionURI)
    121 	suite.Equal(testAccountBefore.ActorType, testAccountAfter.ActorType)
    122 	suite.Equal(testAccountBefore.PrivateKey, testAccountAfter.PrivateKey)
    123 	suite.Equal(testAccountBefore.PublicKey, testAccountAfter.PublicKey)
    124 	suite.Equal(testAccountBefore.PublicKeyURI, testAccountAfter.PublicKeyURI)
    125 	suite.Equal(testAccountBefore.SuspendedAt, testAccountAfter.SuspendedAt)
    126 	suite.Equal(testAccountBefore.HideCollections, testAccountAfter.HideCollections)
    127 	suite.Equal(testAccountBefore.SuspensionOrigin, testAccountAfter.SuspensionOrigin)
    128 }
    129 
    130 func TestImportMinimalTestSuite(t *testing.T) {
    131 	suite.Run(t, &ImportMinimalTestSuite{})
    132 }