diff options
| author | 2023-08-07 19:38:11 +0200 | |
|---|---|---|
| committer | 2023-08-07 18:38:11 +0100 | |
| commit | be3718f6e4c7bb229f9eb78b44c52d14399977cc (patch) | |
| tree | a0efc132fbfb806227cc4b9af8bac9f5a5775c1c /internal/db/bundb | |
| parent | [chore]: Bump github.com/tdewolff/minify/v2 from 2.12.7 to 2.12.8 (#2073) (diff) | |
| download | gotosocial-be3718f6e4c7bb229f9eb78b44c52d14399977cc.tar.xz | |
[chore] Use generic pointer function (#2080)
This replaces the different $TypePtr functions with a generic
implementation.
Diffstat (limited to 'internal/db/bundb')
| -rw-r--r-- | internal/db/bundb/admin.go | 9 | ||||
| -rw-r--r-- | internal/db/bundb/instance_test.go | 8 | ||||
| -rw-r--r-- | internal/db/bundb/notification_test.go | 4 | ||||
| -rw-r--r-- | internal/db/bundb/relationship_test.go | 4 | ||||
| -rw-r--r-- | internal/db/bundb/report_test.go | 3 | ||||
| -rw-r--r-- | internal/db/bundb/timeline_test.go | 14 | 
6 files changed, 21 insertions, 21 deletions
| diff --git a/internal/db/bundb/admin.go b/internal/db/bundb/admin.go index fb1fb9d6c..723648a9e 100644 --- a/internal/db/bundb/admin.go +++ b/internal/db/bundb/admin.go @@ -36,6 +36,7 @@ import (  	"github.com/superseriousbusiness/gotosocial/internal/log"  	"github.com/superseriousbusiness/gotosocial/internal/state"  	"github.com/superseriousbusiness/gotosocial/internal/uris" +	"github.com/superseriousbusiness/gotosocial/internal/util"  	"github.com/uptrace/bun"  	"golang.org/x/crypto/bcrypt"  ) @@ -198,17 +199,15 @@ func (a *adminDB) NewSignup(ctx context.Context, newSignup gtsmodel.NewSignup) (  		user.Email = newSignup.Email  	} -	trueBool := func() *bool { t := true; return &t } -  	if newSignup.Admin {  		// Make new user mod + admin. -		user.Moderator = trueBool() -		user.Admin = trueBool() +		user.Moderator = util.Ptr(true) +		user.Admin = util.Ptr(true)  	}  	if newSignup.PreApproved {  		// Mark new user as approved. -		user.Approved = trueBool() +		user.Approved = util.Ptr(true)  	}  	// Insert the user! diff --git a/internal/db/bundb/instance_test.go b/internal/db/bundb/instance_test.go index 580a7699b..a825a3341 100644 --- a/internal/db/bundb/instance_test.go +++ b/internal/db/bundb/instance_test.go @@ -25,7 +25,7 @@ import (  	"github.com/superseriousbusiness/gotosocial/internal/config"  	"github.com/superseriousbusiness/gotosocial/internal/db"  	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel" -	"github.com/superseriousbusiness/gotosocial/testrig" +	"github.com/superseriousbusiness/gotosocial/internal/util"  )  type InstanceTestSuite struct { @@ -103,7 +103,7 @@ func (suite *InstanceTestSuite) TestGetInstanceModeratorAddressesZorkAsModerator  	// Promote zork to moderator role.  	testUser := >smodel.User{}  	*testUser = *suite.testUsers["local_account_1"] -	testUser.Moderator = testrig.TrueBool() +	testUser.Moderator = util.Ptr(true)  	if err := suite.db.UpdateUser(context.Background(), testUser, "moderator"); err != nil {  		suite.FailNow(err.Error())  	} @@ -117,8 +117,8 @@ func (suite *InstanceTestSuite) TestGetInstanceModeratorAddressesNoAdmin() {  	// Demote admin from admin + moderator roles.  	testUser := >smodel.User{}  	*testUser = *suite.testUsers["admin_account"] -	testUser.Admin = testrig.FalseBool() -	testUser.Moderator = testrig.FalseBool() +	testUser.Admin = util.Ptr(false) +	testUser.Moderator = util.Ptr(false)  	if err := suite.db.UpdateUser(context.Background(), testUser, "admin", "moderator"); err != nil {  		suite.FailNow(err.Error())  	} diff --git a/internal/db/bundb/notification_test.go b/internal/db/bundb/notification_test.go index 8bbea78ad..e27475476 100644 --- a/internal/db/bundb/notification_test.go +++ b/internal/db/bundb/notification_test.go @@ -28,7 +28,7 @@ import (  	"github.com/superseriousbusiness/gotosocial/internal/db"  	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"  	"github.com/superseriousbusiness/gotosocial/internal/id" -	"github.com/superseriousbusiness/gotosocial/testrig" +	"github.com/superseriousbusiness/gotosocial/internal/util"  )  func (suite *NotificationTestSuite) spamNotifs() { @@ -70,7 +70,7 @@ func (suite *NotificationTestSuite) spamNotifs() {  			TargetAccountID:  targetAccountID,  			OriginAccountID:  originAccountID,  			StatusID:         statusID, -			Read:             testrig.FalseBool(), +			Read:             util.Ptr(false),  		}  		if err := suite.db.Put(context.Background(), notif); err != nil { diff --git a/internal/db/bundb/relationship_test.go b/internal/db/bundb/relationship_test.go index cf2df5144..d7c93ff0e 100644 --- a/internal/db/bundb/relationship_test.go +++ b/internal/db/bundb/relationship_test.go @@ -28,7 +28,7 @@ import (  	"github.com/superseriousbusiness/gotosocial/internal/db"  	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"  	"github.com/superseriousbusiness/gotosocial/internal/id" -	"github.com/superseriousbusiness/gotosocial/testrig" +	"github.com/superseriousbusiness/gotosocial/internal/util"  )  type RelationshipTestSuite struct { @@ -892,7 +892,7 @@ func (suite *RelationshipTestSuite) TestUpdateFollow() {  	follow := >smodel.Follow{}  	*follow = *suite.testFollows["local_account_1_admin_account"] -	follow.Notify = testrig.TrueBool() +	follow.Notify = util.Ptr(true)  	if err := suite.db.UpdateFollow(ctx, follow, "notify"); err != nil {  		suite.FailNow(err.Error())  	} diff --git a/internal/db/bundb/report_test.go b/internal/db/bundb/report_test.go index c5ec070e0..594b0b7aa 100644 --- a/internal/db/bundb/report_test.go +++ b/internal/db/bundb/report_test.go @@ -24,6 +24,7 @@ import (  	"github.com/stretchr/testify/suite"  	"github.com/superseriousbusiness/gotosocial/internal/db"  	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel" +	"github.com/superseriousbusiness/gotosocial/internal/util"  	"github.com/superseriousbusiness/gotosocial/testrig"  ) @@ -88,7 +89,7 @@ func (suite *ReportTestSuite) TestPutReport() {  		TargetAccountID: "01F8MH5ZK5VRH73AKHQM6Y9VNX",  		Comment:         "another report",  		StatusIDs:       []string{"01FVW7JHQFSFK166WWKR8CBA6M"}, -		Forwarded:       testrig.TrueBool(), +		Forwarded:       util.Ptr(true),  	}  	err := suite.db.PutReport(ctx, report) diff --git a/internal/db/bundb/timeline_test.go b/internal/db/bundb/timeline_test.go index 43407bc69..2bc9c9d0d 100644 --- a/internal/db/bundb/timeline_test.go +++ b/internal/db/bundb/timeline_test.go @@ -26,7 +26,7 @@ import (  	"github.com/superseriousbusiness/gotosocial/internal/ap"  	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"  	"github.com/superseriousbusiness/gotosocial/internal/id" -	"github.com/superseriousbusiness/gotosocial/testrig" +	"github.com/superseriousbusiness/gotosocial/internal/util"  )  type TimelineTestSuite struct { @@ -52,20 +52,20 @@ func getFutureStatus() *gtsmodel.Status {  		EmojiIDs:                 []string{},  		CreatedAt:                theDistantFuture,  		UpdatedAt:                theDistantFuture, -		Local:                    testrig.TrueBool(), +		Local:                    util.Ptr(true),  		AccountURI:               "http://localhost:8080/users/admin",  		AccountID:                "01F8MH17FWEB39HZJ76B6VXSKF",  		InReplyToID:              "",  		BoostOfID:                "",  		ContentWarning:           "",  		Visibility:               gtsmodel.VisibilityPublic, -		Sensitive:                testrig.FalseBool(), +		Sensitive:                util.Ptr(false),  		Language:                 "en",  		CreatedWithApplicationID: "01F8MGXQRHYF5QPMTMXP78QC2F", -		Federated:                testrig.TrueBool(), -		Boostable:                testrig.TrueBool(), -		Replyable:                testrig.TrueBool(), -		Likeable:                 testrig.TrueBool(), +		Federated:                util.Ptr(true), +		Boostable:                util.Ptr(true), +		Replyable:                util.Ptr(true), +		Likeable:                 util.Ptr(true),  		ActivityStreamsType:      ap.ObjectNote,  	}  } | 
