summaryrefslogtreecommitdiff
path: root/internal/db/bundb/status_test.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-03-02 16:58:23 +0100
committerLibravatar GitHub <noreply@github.com>2023-03-02 16:58:23 +0100
commitbfccf4e450d22d9a3fc0c58d94ed728207d305e0 (patch)
tree4a96323881ffcff8af293f90370b9464ae044160 /internal/db/bundb/status_test.go
parent[feature] Advertise rich text formats, support content_type field (#1370) (diff)
downloadgotosocial-bfccf4e450d22d9a3fc0c58d94ed728207d305e0.tar.xz
[bugfix] add ON CONFLICT statements to status updates (#1580)
Diffstat (limited to 'internal/db/bundb/status_test.go')
-rw-r--r--internal/db/bundb/status_test.go31
1 files changed, 30 insertions, 1 deletions
diff --git a/internal/db/bundb/status_test.go b/internal/db/bundb/status_test.go
index d86e0bcf9..2335c75a9 100644
--- a/internal/db/bundb/status_test.go
+++ b/internal/db/bundb/status_test.go
@@ -26,6 +26,7 @@ import (
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/db"
+ "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
)
type StatusTestSuite struct {
@@ -176,7 +177,10 @@ func (suite *StatusTestSuite) TestGetStatusChildren() {
}
func (suite *StatusTestSuite) TestDeleteStatus() {
- targetStatus := suite.testStatuses["admin_account_status_1"]
+ // Take a copy of the status.
+ targetStatus := &gtsmodel.Status{}
+ *targetStatus = *suite.testStatuses["admin_account_status_1"]
+
err := suite.db.DeleteStatusByID(context.Background(), targetStatus.ID)
suite.NoError(err)
@@ -184,6 +188,31 @@ func (suite *StatusTestSuite) TestDeleteStatus() {
suite.ErrorIs(err, db.ErrNoEntries)
}
+// This test was added specifically to ensure that Postgres wasn't getting upset
+// about trying to use a transaction in which an error has already occurred, which
+// was previously leading to errors like 'current transaction is aborted, commands
+// ignored until end of transaction block' when updating a status that already had
+// emojis or tags set on it.
+//
+// To run this test for postgres specifically, start a postgres container on localhost
+// and then run:
+//
+// GTS_DB_TYPE=postgres GTS_DB_ADDRESS=localhost go test ./internal/db/bundb -run '^TestStatusTestSuite$' -testify.m '^(TestUpdateStatus)$' github.com/superseriousbusiness/gotosocial/internal/db/bundb
+func (suite *StatusTestSuite) TestUpdateStatus() {
+ // Take a copy of the status.
+ targetStatus := &gtsmodel.Status{}
+ *targetStatus = *suite.testStatuses["admin_account_status_1"]
+
+ targetStatus.PinnedAt = time.Time{}
+
+ err := suite.db.UpdateStatus(context.Background(), targetStatus, "pinned_at")
+ suite.NoError(err)
+
+ updated, err := suite.db.GetStatusByID(context.Background(), targetStatus.ID)
+ suite.NoError(err)
+ suite.True(updated.PinnedAt.IsZero())
+}
+
func TestStatusTestSuite(t *testing.T) {
suite.Run(t, new(StatusTestSuite))
}