2021-08-20 13:26:56 +03:00
|
|
|
/*
|
|
|
|
GoToSocial
|
2021-12-20 20:42:19 +03:00
|
|
|
Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org
|
2021-08-20 13:26:56 +03:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2021-08-25 16:34:33 +03:00
|
|
|
package bundb_test
|
2021-08-20 13:26:56 +03:00
|
|
|
|
|
|
|
import (
|
2021-08-25 16:34:33 +03:00
|
|
|
"context"
|
2021-08-20 13:26:56 +03:00
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
2022-09-21 20:55:52 +03:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
2021-08-20 13:26:56 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type StatusTestSuite struct {
|
2021-08-25 16:34:33 +03:00
|
|
|
BunDBStandardTestSuite
|
2021-08-20 13:26:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *StatusTestSuite) TestGetStatusByID() {
|
2021-08-25 16:34:33 +03:00
|
|
|
status, err := suite.db.GetStatusByID(context.Background(), suite.testStatuses["local_account_1_status_1"].ID)
|
2021-08-20 13:26:56 +03:00
|
|
|
if err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
suite.NotNil(status)
|
|
|
|
suite.NotNil(status.Account)
|
|
|
|
suite.NotNil(status.CreatedWithApplication)
|
|
|
|
suite.Nil(status.BoostOf)
|
|
|
|
suite.Nil(status.BoostOfAccount)
|
|
|
|
suite.Nil(status.InReplyTo)
|
|
|
|
suite.Nil(status.InReplyToAccount)
|
2022-08-15 13:35:05 +03:00
|
|
|
suite.True(*status.Federated)
|
|
|
|
suite.True(*status.Boostable)
|
|
|
|
suite.True(*status.Replyable)
|
|
|
|
suite.True(*status.Likeable)
|
2021-08-20 13:26:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *StatusTestSuite) TestGetStatusByURI() {
|
2021-09-09 17:15:25 +03:00
|
|
|
status, err := suite.db.GetStatusByURI(context.Background(), suite.testStatuses["local_account_2_status_3"].URI)
|
2021-08-20 13:26:56 +03:00
|
|
|
if err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
suite.NotNil(status)
|
|
|
|
suite.NotNil(status.Account)
|
|
|
|
suite.NotNil(status.CreatedWithApplication)
|
|
|
|
suite.Nil(status.BoostOf)
|
|
|
|
suite.Nil(status.BoostOfAccount)
|
|
|
|
suite.Nil(status.InReplyTo)
|
|
|
|
suite.Nil(status.InReplyToAccount)
|
2022-08-15 13:35:05 +03:00
|
|
|
suite.True(*status.Federated)
|
|
|
|
suite.True(*status.Boostable)
|
|
|
|
suite.False(*status.Replyable)
|
|
|
|
suite.False(*status.Likeable)
|
2021-08-20 13:26:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *StatusTestSuite) TestGetStatusWithExtras() {
|
2021-08-25 16:34:33 +03:00
|
|
|
status, err := suite.db.GetStatusByID(context.Background(), suite.testStatuses["admin_account_status_1"].ID)
|
2021-08-20 13:26:56 +03:00
|
|
|
if err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
suite.NotNil(status)
|
|
|
|
suite.NotNil(status.Account)
|
|
|
|
suite.NotNil(status.CreatedWithApplication)
|
|
|
|
suite.NotEmpty(status.Tags)
|
|
|
|
suite.NotEmpty(status.Attachments)
|
|
|
|
suite.NotEmpty(status.Emojis)
|
2022-08-15 13:35:05 +03:00
|
|
|
suite.True(*status.Federated)
|
|
|
|
suite.True(*status.Boostable)
|
|
|
|
suite.True(*status.Replyable)
|
|
|
|
suite.True(*status.Likeable)
|
2021-08-20 13:26:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *StatusTestSuite) TestGetStatusWithMention() {
|
2021-08-25 16:34:33 +03:00
|
|
|
status, err := suite.db.GetStatusByID(context.Background(), suite.testStatuses["local_account_2_status_5"].ID)
|
2021-08-20 13:26:56 +03:00
|
|
|
if err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
suite.NotNil(status)
|
|
|
|
suite.NotNil(status.Account)
|
|
|
|
suite.NotNil(status.CreatedWithApplication)
|
|
|
|
suite.NotEmpty(status.MentionIDs)
|
2021-09-01 12:08:21 +03:00
|
|
|
suite.NotEmpty(status.InReplyToID)
|
|
|
|
suite.NotEmpty(status.InReplyToAccountID)
|
2022-08-15 13:35:05 +03:00
|
|
|
suite.True(*status.Federated)
|
|
|
|
suite.True(*status.Boostable)
|
|
|
|
suite.True(*status.Replyable)
|
|
|
|
suite.True(*status.Likeable)
|
2021-08-20 13:26:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *StatusTestSuite) TestGetStatusTwice() {
|
|
|
|
before1 := time.Now()
|
2021-08-25 16:34:33 +03:00
|
|
|
_, err := suite.db.GetStatusByURI(context.Background(), suite.testStatuses["local_account_1_status_1"].URI)
|
2021-08-20 13:26:56 +03:00
|
|
|
suite.NoError(err)
|
|
|
|
after1 := time.Now()
|
|
|
|
duration1 := after1.Sub(before1)
|
2022-10-08 14:50:48 +03:00
|
|
|
fmt.Println(duration1.Microseconds())
|
2021-08-20 13:26:56 +03:00
|
|
|
|
|
|
|
before2 := time.Now()
|
2021-08-25 16:34:33 +03:00
|
|
|
_, err = suite.db.GetStatusByURI(context.Background(), suite.testStatuses["local_account_1_status_1"].URI)
|
2021-08-20 13:26:56 +03:00
|
|
|
suite.NoError(err)
|
|
|
|
after2 := time.Now()
|
|
|
|
duration2 := after2.Sub(before2)
|
2022-10-08 14:50:48 +03:00
|
|
|
fmt.Println(duration2.Microseconds())
|
2021-08-20 13:26:56 +03:00
|
|
|
|
|
|
|
// second retrieval should be several orders faster since it will be cached now
|
|
|
|
suite.Less(duration2, duration1)
|
|
|
|
}
|
|
|
|
|
2021-09-09 17:15:25 +03:00
|
|
|
func (suite *StatusTestSuite) TestGetStatusChildren() {
|
|
|
|
targetStatus := suite.testStatuses["local_account_1_status_1"]
|
|
|
|
children, err := suite.db.GetStatusChildren(context.Background(), targetStatus, true, "")
|
|
|
|
suite.NoError(err)
|
|
|
|
suite.Len(children, 2)
|
|
|
|
for _, c := range children {
|
|
|
|
suite.Equal(targetStatus.URI, c.InReplyToURI)
|
|
|
|
suite.Equal(targetStatus.AccountID, c.InReplyToAccountID)
|
|
|
|
suite.Equal(targetStatus.ID, c.InReplyToID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-21 20:55:52 +03:00
|
|
|
func (suite *StatusTestSuite) TestDeleteStatus() {
|
|
|
|
targetStatus := suite.testStatuses["admin_account_status_1"]
|
|
|
|
err := suite.db.DeleteStatusByID(context.Background(), targetStatus.ID)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
_, err = suite.db.GetStatusByID(context.Background(), targetStatus.ID)
|
|
|
|
suite.ErrorIs(err, db.ErrNoEntries)
|
|
|
|
}
|
|
|
|
|
2021-08-20 13:26:56 +03:00
|
|
|
func TestStatusTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(StatusTestSuite))
|
|
|
|
}
|