mirror of
1
Fork 0

Review changes

This commit is contained in:
tsmethurst 2021-09-03 10:30:40 +02:00
parent dfb9d63123
commit a116676814
28 changed files with 282 additions and 270 deletions

View File

@ -165,19 +165,19 @@ func (d *deref) dereferenceAccountable(ctx context.Context, username string, rem
}
switch t.GetTypeName() {
case string(ap.ActorPerson):
case ap.ActorPerson:
p, ok := t.(vocab.ActivityStreamsPerson)
if !ok {
return nil, errors.New("DereferenceAccountable: error resolving type as activitystreams person")
}
return p, nil
case string(ap.ActorApplication):
case ap.ActorApplication:
p, ok := t.(vocab.ActivityStreamsApplication)
if !ok {
return nil, errors.New("DereferenceAccountable: error resolving type as activitystreams application")
}
return p, nil
case string(ap.ActorService):
case ap.ActorService:
p, ok := t.(vocab.ActivityStreamsService)
if !ok {
return nil, errors.New("DereferenceAccountable: error resolving type as activitystreams service")

View File

@ -118,7 +118,7 @@ func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsA
}
switch iter.GetType().GetTypeName() {
// we have the whole object so we can figure out what we're accepting
case string(ap.ActivityFollow):
case ap.ActivityFollow:
// ACCEPT FOLLOW
asFollow, ok := iter.GetType().(vocab.ActivityStreamsFollow)
if !ok {

View File

@ -73,7 +73,7 @@ func (f *federatingDB) Undo(ctx context.Context, undo vocab.ActivityStreamsUndo)
continue
}
switch iter.GetType().GetTypeName() {
case string(ap.ActivityFollow):
case ap.ActivityFollow:
// UNDO FOLLOW
ASFollow, ok := iter.GetType().(vocab.ActivityStreamsFollow)
if !ok {
@ -102,11 +102,11 @@ func (f *federatingDB) Undo(ctx context.Context, undo vocab.ActivityStreamsUndo)
}
l.Debug("follow undone")
return nil
case string(ap.ActivityLike):
case ap.ActivityLike:
// UNDO LIKE
case string(ap.ActivityAnnounce):
case ap.ActivityAnnounce:
// UNDO BOOST/REBLOG/ANNOUNCE
case string(ap.ActivityBlock):
case ap.ActivityBlock:
// UNDO BLOCK
ASBlock, ok := iter.GetType().(vocab.ActivityStreamsBlock)
if !ok {

View File

@ -29,7 +29,7 @@ type Application struct {
Name string `validate:"required" bun:",nullzero,notnull"` // name of the application given when it was created (eg., 'tusky')
Website string `validate:"omitempty,url" bun:",nullzero"` // website for the application given when it was created (eg., 'https://tusky.app')
RedirectURI string `validate:"required,uri" bun:",nullzero,notnull"` // redirect uri requested by the application for oauth2 flow
ClientID string `validate:"omitempty,ulid" bun:"type:CHAR(26),nullzero"` // id of the associated oauth client entity in the db
ClientID string `validate:"required,ulid" bun:"type:CHAR(26),nullzero,notnull"` // id of the associated oauth client entity in the db
ClientSecret string `validate:"required,uuid" bun:",nullzero,notnull"` // secret of the associated oauth client entity in the db
Scopes string `validate:"-" bun:",nullzero,notnull,default:'read'"` // scopes requested when this app was created
Scopes string `validate:"required" bun:",nullzero,notnull"` // scopes requested when this app was created
}

View File

@ -28,7 +28,7 @@ type Token struct {
ClientID string `validate:"required,ulid" bun:"type:CHAR(26),nullzero,notnull"` // ID of the client who owns this token
UserID string `validate:"required,ulid" bun:"type:CHAR(26),nullzero,notnull"` // ID of the user who owns this token
RedirectURI string `validate:"required,uri" bun:",nullzero,notnull"` // Oauth redirect URI for this token
Scope string `validate:"omitempty" bun:",nullzero,notnull,default:'read'"` // Oauth scope
Scope string `validate:"required" bun:",nullzero,notnull"` // Oauth scope
Code string `validate:"-" bun:",pk,nullzero,notnull,default:''"` // Code, if present
CodeChallenge string `validate:"-" bun:",nullzero"` // Code challenge, if code present
CodeChallengeMethod string `validate:"-" bun:",nullzero"` // Code challenge method, if code present

View File

@ -38,7 +38,7 @@ type User struct {
CurrentSignInIP net.IP `validate:"-" bun:",nullzero"` // What's the most recent IP of this user
LastSignInAt time.Time `validate:"-" bun:"type:timestamp,nullzero"` // When did this user last sign in?
LastSignInIP net.IP `validate:"-" bun:",nullzero"` // What's the previous IP of this user?
SignInCount int `validate:"-" bun:",nullzero,notnull,default:0"` // How many times has this user signed in?
SignInCount int `validate:"min=0" bun:",nullzero,notnull,default:0"` // How many times has this user signed in?
InviteID string `validate:"omitempty,ulid" bun:"type:CHAR(26),nullzero"` // id of the user who invited this user (who let this joker in?)
ChosenLanguages []string `validate:"-" bun:",nullzero"` // What languages does this user want to see?
FilteredLanguages []string `validate:"-" bun:",nullzero"` // What languages does this user not want to see?

View File

@ -48,7 +48,7 @@ type ApplicationValidateTestSuite struct {
func (suite *ApplicationValidateTestSuite) TestValidateApplicationHappyPath() {
// no problem here
a := happyApplication()
err := validate.Struct(*a)
err := validate.Struct(a)
suite.NoError(err)
}
@ -56,11 +56,11 @@ func (suite *ApplicationValidateTestSuite) TestValidateApplicationBadID() {
a := happyApplication()
a.ID = ""
err := validate.Struct(*a)
err := validate.Struct(a)
suite.EqualError(err, "Key: 'Application.ID' Error:Field validation for 'ID' failed on the 'required' tag")
a.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB"
err = validate.Struct(*a)
err = validate.Struct(a)
suite.EqualError(err, "Key: 'Application.ID' Error:Field validation for 'ID' failed on the 'ulid' tag")
}
@ -68,7 +68,7 @@ func (suite *ApplicationValidateTestSuite) TestValidateApplicationNoCreatedAt()
a := happyApplication()
a.CreatedAt = time.Time{}
err := validate.Struct(*a)
err := validate.Struct(a)
suite.NoError(err)
}
@ -76,7 +76,7 @@ func (suite *ApplicationValidateTestSuite) TestValidateApplicationName() {
a := happyApplication()
a.Name = ""
err := validate.Struct(*a)
err := validate.Struct(a)
suite.EqualError(err, "Key: 'Application.Name' Error:Field validation for 'Name' failed on the 'required' tag")
}
@ -84,11 +84,11 @@ func (suite *ApplicationValidateTestSuite) TestValidateApplicationWebsite() {
a := happyApplication()
a.Website = "invalid-website"
err := validate.Struct(*a)
err := validate.Struct(a)
suite.EqualError(err, "Key: 'Application.Website' Error:Field validation for 'Website' failed on the 'url' tag")
a.Website = ""
err = validate.Struct(*a)
err = validate.Struct(a)
suite.NoError(err)
}
@ -96,15 +96,15 @@ func (suite *ApplicationValidateTestSuite) TestValidateApplicationRedirectURI()
a := happyApplication()
a.RedirectURI = "invalid-uri"
err := validate.Struct(*a)
err := validate.Struct(a)
suite.EqualError(err, "Key: 'Application.RedirectURI' Error:Field validation for 'RedirectURI' failed on the 'uri' tag")
a.RedirectURI = ""
err = validate.Struct(*a)
err = validate.Struct(a)
suite.EqualError(err, "Key: 'Application.RedirectURI' Error:Field validation for 'RedirectURI' failed on the 'required' tag")
a.RedirectURI = "urn:ietf:wg:oauth:2.0:oob"
err = validate.Struct(*a)
err = validate.Struct(a)
suite.NoError(err)
}
@ -112,11 +112,11 @@ func (suite *ApplicationValidateTestSuite) TestValidateApplicationClientSecret()
a := happyApplication()
a.ClientSecret = "invalid-uuid"
err := validate.Struct(*a)
err := validate.Struct(a)
suite.EqualError(err, "Key: 'Application.ClientSecret' Error:Field validation for 'ClientSecret' failed on the 'uuid' tag")
a.ClientSecret = ""
err = validate.Struct(*a)
err = validate.Struct(a)
suite.EqualError(err, "Key: 'Application.ClientSecret' Error:Field validation for 'ClientSecret' failed on the 'required' tag")
}
@ -124,8 +124,8 @@ func (suite *ApplicationValidateTestSuite) TestValidateApplicationScopes() {
a := happyApplication()
a.Scopes = ""
err := validate.Struct(*a)
suite.NoError(err)
err := validate.Struct(a)
suite.EqualError(err, "Key: 'Application.Scopes' Error:Field validation for 'Scopes' failed on the 'required' tag")
}
func TestApplicationValidateTestSuite(t *testing.T) {

View File

@ -46,68 +46,68 @@ type BlockValidateTestSuite struct {
func (suite *BlockValidateTestSuite) TestValidateBlockHappyPath() {
// no problem here
d := happyBlock()
err := validate.Struct(*d)
b := happyBlock()
err := validate.Struct(b)
suite.NoError(err)
}
func (suite *BlockValidateTestSuite) TestValidateBlockBadID() {
d := happyBlock()
b := happyBlock()
d.ID = ""
err := validate.Struct(*d)
b.ID = ""
err := validate.Struct(b)
suite.EqualError(err, "Key: 'Block.ID' Error:Field validation for 'ID' failed on the 'required' tag")
d.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB"
err = validate.Struct(*d)
b.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB"
err = validate.Struct(b)
suite.EqualError(err, "Key: 'Block.ID' Error:Field validation for 'ID' failed on the 'ulid' tag")
}
func (suite *BlockValidateTestSuite) TestValidateBlockNoCreatedAt() {
d := happyBlock()
b := happyBlock()
d.CreatedAt = time.Time{}
err := validate.Struct(*d)
b.CreatedAt = time.Time{}
err := validate.Struct(b)
suite.NoError(err)
}
func (suite *BlockValidateTestSuite) TestValidateBlockCreatedByAccountID() {
d := happyBlock()
b := happyBlock()
d.AccountID = ""
err := validate.Struct(*d)
b.AccountID = ""
err := validate.Struct(b)
suite.EqualError(err, "Key: 'Block.AccountID' Error:Field validation for 'AccountID' failed on the 'required' tag")
d.AccountID = "this-is-not-a-valid-ulid"
err = validate.Struct(*d)
b.AccountID = "this-is-not-a-valid-ulid"
err = validate.Struct(b)
suite.EqualError(err, "Key: 'Block.AccountID' Error:Field validation for 'AccountID' failed on the 'ulid' tag")
}
func (suite *BlockValidateTestSuite) TestValidateBlockTargetAccountID() {
d := happyBlock()
b := happyBlock()
d.TargetAccountID = "invalid-ulid"
err := validate.Struct(*d)
b.TargetAccountID = "invalid-ulid"
err := validate.Struct(b)
suite.EqualError(err, "Key: 'Block.TargetAccountID' Error:Field validation for 'TargetAccountID' failed on the 'ulid' tag")
d.TargetAccountID = "01FEEDHX4G7EGHF5GD9E82Y51Q"
err = validate.Struct(*d)
b.TargetAccountID = "01FEEDHX4G7EGHF5GD9E82Y51Q"
err = validate.Struct(b)
suite.NoError(err)
d.TargetAccountID = ""
err = validate.Struct(*d)
b.TargetAccountID = ""
err = validate.Struct(b)
suite.EqualError(err, "Key: 'Block.TargetAccountID' Error:Field validation for 'TargetAccountID' failed on the 'required' tag")
}
func (suite *BlockValidateTestSuite) TestValidateBlockURI() {
d := happyBlock()
b := happyBlock()
d.URI = "invalid-uri"
err := validate.Struct(*d)
b.URI = "invalid-uri"
err := validate.Struct(b)
suite.EqualError(err, "Key: 'Block.URI' Error:Field validation for 'URI' failed on the 'url' tag")
d.URI = ""
err = validate.Struct(*d)
b.URI = ""
err = validate.Struct(b)
suite.EqualError(err, "Key: 'Block.URI' Error:Field validation for 'URI' failed on the 'required' tag")
}

View File

@ -45,7 +45,7 @@ type ClientValidateTestSuite struct {
func (suite *ClientValidateTestSuite) TestValidateClientHappyPath() {
// no problem here
c := happyClient()
err := validate.Struct(*c)
err := validate.Struct(c)
suite.NoError(err)
}
@ -53,11 +53,11 @@ func (suite *ClientValidateTestSuite) TestValidateClientBadID() {
c := happyClient()
c.ID = ""
err := validate.Struct(*c)
err := validate.Struct(c)
suite.EqualError(err, "Key: 'Client.ID' Error:Field validation for 'ID' failed on the 'required' tag")
c.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB"
err = validate.Struct(*c)
err = validate.Struct(c)
suite.EqualError(err, "Key: 'Client.ID' Error:Field validation for 'ID' failed on the 'ulid' tag")
}
@ -65,7 +65,7 @@ func (suite *ClientValidateTestSuite) TestValidateClientNoCreatedAt() {
c := happyClient()
c.CreatedAt = time.Time{}
err := validate.Struct(*c)
err := validate.Struct(c)
suite.NoError(err)
}
@ -73,27 +73,27 @@ func (suite *ClientValidateTestSuite) TestValidateClientDomain() {
c := happyClient()
c.Domain = "invalid-uri"
err := validate.Struct(*c)
err := validate.Struct(c)
suite.EqualError(err, "Key: 'Client.Domain' Error:Field validation for 'Domain' failed on the 'uri' tag")
c.Domain = ""
err = validate.Struct(*c)
err = validate.Struct(c)
suite.EqualError(err, "Key: 'Client.Domain' Error:Field validation for 'Domain' failed on the 'required' tag")
c.Domain = "urn:ietf:wg:oauth:2.0:oob"
err = validate.Struct(*c)
err = validate.Struct(c)
suite.NoError(err)
}
func (suite *ClientValidateTestSuite) TestValidateSecret() {
a := happyClient()
c := happyClient()
a.Secret = "invalid-uuid"
err := validate.Struct(*a)
c.Secret = "invalid-uuid"
err := validate.Struct(c)
suite.EqualError(err, "Key: 'Client.Secret' Error:Field validation for 'Secret' failed on the 'uuid' tag")
a.Secret = ""
err = validate.Struct(*a)
c.Secret = ""
err = validate.Struct(c)
suite.EqualError(err, "Key: 'Client.Secret' Error:Field validation for 'Secret' failed on the 'required' tag")
}

View File

@ -48,7 +48,7 @@ type DomainBlockValidateTestSuite struct {
func (suite *DomainBlockValidateTestSuite) TestValidateDomainBlockHappyPath() {
// no problem here
d := happyDomainBlock()
err := validate.Struct(*d)
err := validate.Struct(d)
suite.NoError(err)
}
@ -56,11 +56,11 @@ func (suite *DomainBlockValidateTestSuite) TestValidateDomainBlockBadID() {
d := happyDomainBlock()
d.ID = ""
err := validate.Struct(*d)
err := validate.Struct(d)
suite.EqualError(err, "Key: 'DomainBlock.ID' Error:Field validation for 'ID' failed on the 'required' tag")
d.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB"
err = validate.Struct(*d)
err = validate.Struct(d)
suite.EqualError(err, "Key: 'DomainBlock.ID' Error:Field validation for 'ID' failed on the 'ulid' tag")
}
@ -68,7 +68,7 @@ func (suite *DomainBlockValidateTestSuite) TestValidateDomainBlockNoCreatedAt()
d := happyDomainBlock()
d.CreatedAt = time.Time{}
err := validate.Struct(*d)
err := validate.Struct(d)
suite.NoError(err)
}
@ -76,11 +76,11 @@ func (suite *DomainBlockValidateTestSuite) TestValidateDomainBlockBadDomain() {
d := happyDomainBlock()
d.Domain = ""
err := validate.Struct(*d)
err := validate.Struct(d)
suite.EqualError(err, "Key: 'DomainBlock.Domain' Error:Field validation for 'Domain' failed on the 'required' tag")
d.Domain = "this-is-not-a-valid-domain"
err = validate.Struct(*d)
err = validate.Struct(d)
suite.EqualError(err, "Key: 'DomainBlock.Domain' Error:Field validation for 'Domain' failed on the 'fqdn' tag")
}
@ -88,11 +88,11 @@ func (suite *DomainBlockValidateTestSuite) TestValidateDomainBlockCreatedByAccou
d := happyDomainBlock()
d.CreatedByAccountID = ""
err := validate.Struct(*d)
err := validate.Struct(d)
suite.EqualError(err, "Key: 'DomainBlock.CreatedByAccountID' Error:Field validation for 'CreatedByAccountID' failed on the 'required' tag")
d.CreatedByAccountID = "this-is-not-a-valid-ulid"
err = validate.Struct(*d)
err = validate.Struct(d)
suite.EqualError(err, "Key: 'DomainBlock.CreatedByAccountID' Error:Field validation for 'CreatedByAccountID' failed on the 'ulid' tag")
}
@ -101,7 +101,7 @@ func (suite *DomainBlockValidateTestSuite) TestValidateDomainBlockComments() {
d.PrivateComment = ""
d.PublicComment = ""
err := validate.Struct(*d)
err := validate.Struct(d)
suite.NoError(err)
}
@ -109,11 +109,11 @@ func (suite *DomainBlockValidateTestSuite) TestValidateDomainSubscriptionID() {
d := happyDomainBlock()
d.SubscriptionID = "invalid-ulid"
err := validate.Struct(*d)
err := validate.Struct(d)
suite.EqualError(err, "Key: 'DomainBlock.SubscriptionID' Error:Field validation for 'SubscriptionID' failed on the 'ulid' tag")
d.SubscriptionID = "01FEEDHX4G7EGHF5GD9E82Y51Q"
err = validate.Struct(*d)
err = validate.Struct(d)
suite.NoError(err)
}

View File

@ -44,7 +44,7 @@ type EmailDomainBlockValidateTestSuite struct {
func (suite *EmailDomainBlockValidateTestSuite) TestValidateEmailDomainBlockHappyPath() {
// no problem here
e := happyEmailDomainBlock()
err := validate.Struct(*e)
err := validate.Struct(e)
suite.NoError(err)
}
@ -52,11 +52,11 @@ func (suite *EmailDomainBlockValidateTestSuite) TestValidateEmailDomainBlockBadI
e := happyEmailDomainBlock()
e.ID = ""
err := validate.Struct(*e)
err := validate.Struct(e)
suite.EqualError(err, "Key: 'EmailDomainBlock.ID' Error:Field validation for 'ID' failed on the 'required' tag")
e.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB"
err = validate.Struct(*e)
err = validate.Struct(e)
suite.EqualError(err, "Key: 'EmailDomainBlock.ID' Error:Field validation for 'ID' failed on the 'ulid' tag")
}
@ -64,7 +64,7 @@ func (suite *EmailDomainBlockValidateTestSuite) TestValidateEmailDomainBlockNoCr
e := happyEmailDomainBlock()
e.CreatedAt = time.Time{}
err := validate.Struct(*e)
err := validate.Struct(e)
suite.NoError(err)
}
@ -72,11 +72,11 @@ func (suite *EmailDomainBlockValidateTestSuite) TestValidateEmailDomainBlockBadD
e := happyEmailDomainBlock()
e.Domain = ""
err := validate.Struct(*e)
err := validate.Struct(e)
suite.EqualError(err, "Key: 'EmailDomainBlock.Domain' Error:Field validation for 'Domain' failed on the 'required' tag")
e.Domain = "this-is-not-a-valid-domain"
err = validate.Struct(*e)
err = validate.Struct(e)
suite.EqualError(err, "Key: 'EmailDomainBlock.Domain' Error:Field validation for 'Domain' failed on the 'fqdn' tag")
}
@ -84,11 +84,11 @@ func (suite *EmailDomainBlockValidateTestSuite) TestValidateEmailDomainBlockCrea
e := happyEmailDomainBlock()
e.CreatedByAccountID = ""
err := validate.Struct(*e)
err := validate.Struct(e)
suite.EqualError(err, "Key: 'EmailDomainBlock.CreatedByAccountID' Error:Field validation for 'CreatedByAccountID' failed on the 'required' tag")
e.CreatedByAccountID = "this-is-not-a-valid-ulid"
err = validate.Struct(*e)
err = validate.Struct(e)
suite.EqualError(err, "Key: 'EmailDomainBlock.CreatedByAccountID' Error:Field validation for 'CreatedByAccountID' failed on the 'ulid' tag")
}

View File

@ -95,27 +95,27 @@ func (suite *EmojiValidateTestSuite) TestValidateEmojiBadFilePaths() {
e := happyEmoji()
e.ImagePath = "/tmp/nonexistent/file/for/gotosocial/test"
err := validate.Struct(*e)
err := validate.Struct(e)
suite.EqualError(err, "Key: 'Emoji.ImagePath' Error:Field validation for 'ImagePath' failed on the 'file' tag")
e.ImagePath = ""
err = validate.Struct(*e)
err = validate.Struct(e)
suite.EqualError(err, "Key: 'Emoji.ImagePath' Error:Field validation for 'ImagePath' failed on the 'required' tag")
e.ImagePath = "???????????thisnot a valid path####"
err = validate.Struct(*e)
err = validate.Struct(e)
suite.EqualError(err, "Key: 'Emoji.ImagePath' Error:Field validation for 'ImagePath' failed on the 'file' tag")
e.ImageStaticPath = "/tmp/nonexistent/file/for/gotosocial/test"
err = validate.Struct(*e)
err = validate.Struct(e)
suite.EqualError(err, "Key: 'Emoji.ImagePath' Error:Field validation for 'ImagePath' failed on the 'file' tag\nKey: 'Emoji.ImageStaticPath' Error:Field validation for 'ImageStaticPath' failed on the 'file' tag")
e.ImageStaticPath = ""
err = validate.Struct(*e)
err = validate.Struct(e)
suite.EqualError(err, "Key: 'Emoji.ImagePath' Error:Field validation for 'ImagePath' failed on the 'file' tag\nKey: 'Emoji.ImageStaticPath' Error:Field validation for 'ImageStaticPath' failed on the 'required' tag")
e.ImageStaticPath = "???????????thisnot a valid path####"
err = validate.Struct(*e)
err = validate.Struct(e)
suite.EqualError(err, "Key: 'Emoji.ImagePath' Error:Field validation for 'ImagePath' failed on the 'file' tag\nKey: 'Emoji.ImageStaticPath' Error:Field validation for 'ImageStaticPath' failed on the 'file' tag")
}
@ -123,11 +123,11 @@ func (suite *EmojiValidateTestSuite) TestValidateEmojiURI() {
e := happyEmoji()
e.URI = "aaaaaaaaaa"
err := validate.Struct(*e)
err := validate.Struct(e)
suite.EqualError(err, "Key: 'Emoji.URI' Error:Field validation for 'URI' failed on the 'url' tag")
e.URI = ""
err = validate.Struct(*e)
err = validate.Struct(e)
suite.EqualError(err, "Key: 'Emoji.URI' Error:Field validation for 'URI' failed on the 'url' tag")
}
@ -135,26 +135,26 @@ func (suite *EmojiValidateTestSuite) TestValidateEmojiURLCombos() {
e := happyEmoji()
e.ImageRemoteURL = ""
err := validate.Struct(*e)
err := validate.Struct(e)
suite.EqualError(err, "Key: 'Emoji.ImageRemoteURL' Error:Field validation for 'ImageRemoteURL' failed on the 'required_without' tag\nKey: 'Emoji.ImageURL' Error:Field validation for 'ImageURL' failed on the 'required_without' tag")
e.ImageURL = "https://whatever.org"
err = validate.Struct(*e)
err = validate.Struct(e)
suite.NoError(err)
e.ImageStaticRemoteURL = ""
err = validate.Struct(*e)
err = validate.Struct(e)
suite.EqualError(err, "Key: 'Emoji.ImageStaticRemoteURL' Error:Field validation for 'ImageStaticRemoteURL' failed on the 'required_without' tag\nKey: 'Emoji.ImageStaticURL' Error:Field validation for 'ImageStaticURL' failed on the 'required_without' tag")
e.ImageStaticURL = "https://whatever.org"
err = validate.Struct(*e)
err = validate.Struct(e)
suite.NoError(err)
e.ImageURL = ""
e.ImageStaticURL = ""
e.ImageRemoteURL = ""
e.ImageStaticRemoteURL = ""
err = validate.Struct(*e)
err = validate.Struct(e)
suite.EqualError(err, "Key: 'Emoji.ImageRemoteURL' Error:Field validation for 'ImageRemoteURL' failed on the 'required_without' tag\nKey: 'Emoji.ImageStaticRemoteURL' Error:Field validation for 'ImageStaticRemoteURL' failed on the 'required_without' tag\nKey: 'Emoji.ImageURL' Error:Field validation for 'ImageURL' failed on the 'required_without' tag\nKey: 'Emoji.ImageStaticURL' Error:Field validation for 'ImageStaticURL' failed on the 'required_without' tag")
}
@ -162,19 +162,19 @@ func (suite *EmojiValidateTestSuite) TestValidateFileSize() {
e := happyEmoji()
e.ImageFileSize = 0
err := validate.Struct(*e)
err := validate.Struct(e)
suite.EqualError(err, "Key: 'Emoji.ImageFileSize' Error:Field validation for 'ImageFileSize' failed on the 'required' tag")
e.ImageStaticFileSize = 0
err = validate.Struct(*e)
err = validate.Struct(e)
suite.EqualError(err, "Key: 'Emoji.ImageFileSize' Error:Field validation for 'ImageFileSize' failed on the 'required' tag\nKey: 'Emoji.ImageStaticFileSize' Error:Field validation for 'ImageStaticFileSize' failed on the 'required' tag")
e.ImageFileSize = -1
err = validate.Struct(*e)
err = validate.Struct(e)
suite.EqualError(err, "Key: 'Emoji.ImageFileSize' Error:Field validation for 'ImageFileSize' failed on the 'min' tag\nKey: 'Emoji.ImageStaticFileSize' Error:Field validation for 'ImageStaticFileSize' failed on the 'required' tag")
e.ImageStaticFileSize = -1
err = validate.Struct(*e)
err = validate.Struct(e)
suite.EqualError(err, "Key: 'Emoji.ImageFileSize' Error:Field validation for 'ImageFileSize' failed on the 'min' tag\nKey: 'Emoji.ImageStaticFileSize' Error:Field validation for 'ImageStaticFileSize' failed on the 'min' tag")
}
@ -182,11 +182,11 @@ func (suite *EmojiValidateTestSuite) TestValidateDomain() {
e := happyEmoji()
e.Domain = ""
err := validate.Struct(*e)
err := validate.Struct(e)
suite.EqualError(err, "Key: 'Emoji.ImageURL' Error:Field validation for 'ImageURL' failed on the 'required_without' tag\nKey: 'Emoji.ImageStaticURL' Error:Field validation for 'ImageStaticURL' failed on the 'required_without' tag")
e.Domain = "aaaaaaaaa"
err = validate.Struct(*e)
err = validate.Struct(e)
suite.EqualError(err, "Key: 'Emoji.Domain' Error:Field validation for 'Domain' failed on the 'fqdn' tag")
}

View File

@ -47,7 +47,7 @@ type FollowValidateTestSuite struct {
func (suite *FollowValidateTestSuite) TestValidateFollowHappyPath() {
// no problem here
f := happyFollow()
err := validate.Struct(*f)
err := validate.Struct(f)
suite.NoError(err)
}
@ -55,11 +55,11 @@ func (suite *FollowValidateTestSuite) TestValidateFollowBadID() {
f := happyFollow()
f.ID = ""
err := validate.Struct(*f)
err := validate.Struct(f)
suite.EqualError(err, "Key: 'Follow.ID' Error:Field validation for 'ID' failed on the 'required' tag")
f.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB"
err = validate.Struct(*f)
err = validate.Struct(f)
suite.EqualError(err, "Key: 'Follow.ID' Error:Field validation for 'ID' failed on the 'ulid' tag")
}
@ -67,7 +67,7 @@ func (suite *FollowValidateTestSuite) TestValidateFollowNoCreatedAt() {
f := happyFollow()
f.CreatedAt = time.Time{}
err := validate.Struct(*f)
err := validate.Struct(f)
suite.NoError(err)
}
@ -75,11 +75,11 @@ func (suite *FollowValidateTestSuite) TestValidateFollowNoURI() {
f := happyFollow()
f.URI = ""
err := validate.Struct(*f)
err := validate.Struct(f)
suite.EqualError(err, "Key: 'Follow.URI' Error:Field validation for 'URI' failed on the 'required' tag")
f.URI = "this-is-not-a-valid-url"
err = validate.Struct(*f)
err = validate.Struct(f)
suite.EqualError(err, "Key: 'Follow.URI' Error:Field validation for 'URI' failed on the 'url' tag")
}

View File

@ -47,7 +47,7 @@ type FollowRequestValidateTestSuite struct {
func (suite *FollowRequestValidateTestSuite) TestValidateFollowRequestHappyPath() {
// no problem here
f := happyFollowRequest()
err := validate.Struct(*f)
err := validate.Struct(f)
suite.NoError(err)
}
@ -55,11 +55,11 @@ func (suite *FollowRequestValidateTestSuite) TestValidateFollowRequestBadID() {
f := happyFollowRequest()
f.ID = ""
err := validate.Struct(*f)
err := validate.Struct(f)
suite.EqualError(err, "Key: 'FollowRequest.ID' Error:Field validation for 'ID' failed on the 'required' tag")
f.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB"
err = validate.Struct(*f)
err = validate.Struct(f)
suite.EqualError(err, "Key: 'FollowRequest.ID' Error:Field validation for 'ID' failed on the 'ulid' tag")
}
@ -67,7 +67,7 @@ func (suite *FollowRequestValidateTestSuite) TestValidateFollowRequestNoCreatedA
f := happyFollowRequest()
f.CreatedAt = time.Time{}
err := validate.Struct(*f)
err := validate.Struct(f)
suite.NoError(err)
}
@ -75,11 +75,11 @@ func (suite *FollowRequestValidateTestSuite) TestValidateFollowRequestNoURI() {
f := happyFollowRequest()
f.URI = ""
err := validate.Struct(*f)
err := validate.Struct(f)
suite.EqualError(err, "Key: 'FollowRequest.URI' Error:Field validation for 'URI' failed on the 'required' tag")
f.URI = "this-is-not-a-valid-url"
err = validate.Struct(*f)
err = validate.Struct(f)
suite.EqualError(err, "Key: 'FollowRequest.URI' Error:Field validation for 'URI' failed on the 'url' tag")
}

View File

@ -77,11 +77,11 @@ func (suite *InstanceValidateTestSuite) TestValidateInstanceAccountURI() {
i := happyInstance()
i.URI = ""
err := validate.Struct(*i)
err := validate.Struct(i)
suite.EqualError(err, "Key: 'Instance.URI' Error:Field validation for 'URI' failed on the 'required' tag")
i.URI = "---------------------------"
err = validate.Struct(*i)
err = validate.Struct(i)
suite.EqualError(err, "Key: 'Instance.URI' Error:Field validation for 'URI' failed on the 'url' tag")
}
@ -89,19 +89,19 @@ func (suite *InstanceValidateTestSuite) TestValidateInstanceDodgyAccountID() {
i := happyInstance()
i.ContactAccountID = "9HZJ76B6VXSKF"
err := validate.Struct(*i)
err := validate.Struct(i)
suite.EqualError(err, "Key: 'Instance.ContactAccountID' Error:Field validation for 'ContactAccountID' failed on the 'ulid' tag")
i.ContactAccountID = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!!!!!!!!!!!!"
err = validate.Struct(*i)
err = validate.Struct(i)
suite.EqualError(err, "Key: 'Instance.ContactAccountID' Error:Field validation for 'ContactAccountID' failed on the 'ulid' tag")
i.ContactAccountID = ""
err = validate.Struct(*i)
err = validate.Struct(i)
suite.EqualError(err, "Key: 'Instance.ContactAccountID' Error:Field validation for 'ContactAccountID' failed on the 'required_with' tag")
i.ContactAccountUsername = ""
err = validate.Struct(*i)
err = validate.Struct(i)
suite.NoError(err)
}
@ -109,15 +109,15 @@ func (suite *InstanceValidateTestSuite) TestValidateInstanceDomain() {
i := happyInstance()
i.Domain = "poopoo"
err := validate.Struct(*i)
err := validate.Struct(i)
suite.EqualError(err, "Key: 'Instance.Domain' Error:Field validation for 'Domain' failed on the 'fqdn' tag")
i.Domain = ""
err = validate.Struct(*i)
err = validate.Struct(i)
suite.EqualError(err, "Key: 'Instance.Domain' Error:Field validation for 'Domain' failed on the 'required' tag")
i.Domain = "https://aaaaaaaaaaaaah.org"
err = validate.Struct(*i)
err = validate.Struct(i)
suite.EqualError(err, "Key: 'Instance.Domain' Error:Field validation for 'Domain' failed on the 'fqdn' tag")
}
@ -125,11 +125,11 @@ func (suite *InstanceValidateTestSuite) TestValidateInstanceContactEmail() {
i := happyInstance()
i.ContactEmail = "poopoo"
err := validate.Struct(*i)
err := validate.Struct(i)
suite.EqualError(err, "Key: 'Instance.ContactEmail' Error:Field validation for 'ContactEmail' failed on the 'email' tag")
i.ContactEmail = ""
err = validate.Struct(*i)
err = validate.Struct(i)
suite.NoError(err)
}
@ -137,7 +137,7 @@ func (suite *InstanceValidateTestSuite) TestValidateInstanceNoCreatedAt() {
i := happyInstance()
i.CreatedAt = time.Time{}
err := validate.Struct(*i)
err := validate.Struct(i)
suite.NoError(err)
}

View File

@ -109,7 +109,7 @@ type MediaAttachmentValidateTestSuite struct {
func (suite *MediaAttachmentValidateTestSuite) TestValidateMediaAttachmentHappyPath() {
// no problem here
m := happyMediaAttachment()
err := validate.Struct(*m)
err := validate.Struct(m)
suite.NoError(err)
}
@ -117,27 +117,27 @@ func (suite *MediaAttachmentValidateTestSuite) TestValidateMediaAttachmentBadFil
m := happyMediaAttachment()
m.File.Path = "/tmp/nonexistent/file/for/gotosocial/test"
err := validate.Struct(*m)
err := validate.Struct(m)
suite.EqualError(err, "Key: 'MediaAttachment.File.Path' Error:Field validation for 'Path' failed on the 'file' tag")
m.File.Path = ""
err = validate.Struct(*m)
err = validate.Struct(m)
suite.EqualError(err, "Key: 'MediaAttachment.File.Path' Error:Field validation for 'Path' failed on the 'required' tag")
m.File.Path = "???????????thisnot a valid path####"
err = validate.Struct(*m)
err = validate.Struct(m)
suite.EqualError(err, "Key: 'MediaAttachment.File.Path' Error:Field validation for 'Path' failed on the 'file' tag")
m.Thumbnail.Path = "/tmp/nonexistent/file/for/gotosocial/test"
err = validate.Struct(*m)
err = validate.Struct(m)
suite.EqualError(err, "Key: 'MediaAttachment.File.Path' Error:Field validation for 'Path' failed on the 'file' tag\nKey: 'MediaAttachment.Thumbnail.Path' Error:Field validation for 'Path' failed on the 'file' tag")
m.Thumbnail.Path = ""
err = validate.Struct(*m)
err = validate.Struct(m)
suite.EqualError(err, "Key: 'MediaAttachment.File.Path' Error:Field validation for 'Path' failed on the 'file' tag\nKey: 'MediaAttachment.Thumbnail.Path' Error:Field validation for 'Path' failed on the 'required' tag")
m.Thumbnail.Path = "???????????thisnot a valid path####"
err = validate.Struct(*m)
err = validate.Struct(m)
suite.EqualError(err, "Key: 'MediaAttachment.File.Path' Error:Field validation for 'Path' failed on the 'file' tag\nKey: 'MediaAttachment.Thumbnail.Path' Error:Field validation for 'Path' failed on the 'file' tag")
}
@ -145,11 +145,11 @@ func (suite *MediaAttachmentValidateTestSuite) TestValidateMediaAttachmentBadTyp
m := happyMediaAttachment()
m.Type = ""
err := validate.Struct(*m)
err := validate.Struct(m)
suite.EqualError(err, "Key: 'MediaAttachment.Type' Error:Field validation for 'Type' failed on the 'oneof' tag")
m.Type = "Not Supported"
err = validate.Struct(*m)
err = validate.Struct(m)
suite.EqualError(err, "Key: 'MediaAttachment.Type' Error:Field validation for 'Type' failed on the 'oneof' tag")
}
@ -157,23 +157,23 @@ func (suite *MediaAttachmentValidateTestSuite) TestValidateMediaAttachmentBadFil
m := happyMediaAttachment()
m.FileMeta.Original.Aspect = 0
err := validate.Struct(*m)
err := validate.Struct(m)
suite.EqualError(err, "Key: 'MediaAttachment.FileMeta.Original.Aspect' Error:Field validation for 'Aspect' failed on the 'required_with' tag")
m.FileMeta.Original.Height = 0
err = validate.Struct(*m)
err = validate.Struct(m)
suite.EqualError(err, "Key: 'MediaAttachment.FileMeta.Original.Height' Error:Field validation for 'Height' failed on the 'required_with' tag\nKey: 'MediaAttachment.FileMeta.Original.Aspect' Error:Field validation for 'Aspect' failed on the 'required_with' tag")
m.FileMeta.Original = gtsmodel.Original{}
err = validate.Struct(*m)
err = validate.Struct(m)
suite.NoError(err)
m.FileMeta.Focus.X = 3.6
err = validate.Struct(*m)
err = validate.Struct(m)
suite.EqualError(err, "Key: 'MediaAttachment.FileMeta.Focus.X' Error:Field validation for 'X' failed on the 'max' tag")
m.FileMeta.Focus.Y = -50
err = validate.Struct(*m)
err = validate.Struct(m)
suite.EqualError(err, "Key: 'MediaAttachment.FileMeta.Focus.X' Error:Field validation for 'X' failed on the 'max' tag\nKey: 'MediaAttachment.FileMeta.Focus.Y' Error:Field validation for 'Y' failed on the 'min' tag")
}
@ -181,19 +181,19 @@ func (suite *MediaAttachmentValidateTestSuite) TestValidateMediaAttachmentBadURL
m := happyMediaAttachment()
m.URL = "aaaaaaaaaa"
err := validate.Struct(*m)
err := validate.Struct(m)
suite.EqualError(err, "Key: 'MediaAttachment.URL' Error:Field validation for 'URL' failed on the 'url' tag")
m.URL = ""
err = validate.Struct(*m)
err = validate.Struct(m)
suite.EqualError(err, "Key: 'MediaAttachment.URL' Error:Field validation for 'URL' failed on the 'required_without' tag\nKey: 'MediaAttachment.RemoteURL' Error:Field validation for 'RemoteURL' failed on the 'required_without' tag")
m.RemoteURL = "oooooooooo"
err = validate.Struct(*m)
err = validate.Struct(m)
suite.EqualError(err, "Key: 'MediaAttachment.RemoteURL' Error:Field validation for 'RemoteURL' failed on the 'url' tag")
m.RemoteURL = "https://a-valid-url.gay"
err = validate.Struct(*m)
err = validate.Struct(m)
suite.NoError(err)
}
@ -201,15 +201,15 @@ func (suite *MediaAttachmentValidateTestSuite) TestValidateMediaAttachmentBlurha
m := happyMediaAttachment()
m.Blurhash = ""
err := validate.Struct(*m)
err := validate.Struct(m)
suite.EqualError(err, "Key: 'MediaAttachment.Blurhash' Error:Field validation for 'Blurhash' failed on the 'required_if' tag")
m.Type = gtsmodel.FileTypeAudio
err = validate.Struct(*m)
err = validate.Struct(m)
suite.NoError(err)
m.Blurhash = "some_blurhash"
err = validate.Struct(*m)
err = validate.Struct(m)
suite.NoError(err)
}
@ -217,11 +217,11 @@ func (suite *MediaAttachmentValidateTestSuite) TestValidateMediaAttachmentProces
m := happyMediaAttachment()
m.Processing = 420
err := validate.Struct(*m)
err := validate.Struct(m)
suite.EqualError(err, "Key: 'MediaAttachment.Processing' Error:Field validation for 'Processing' failed on the 'oneof' tag")
m.Processing = -5
err = validate.Struct(*m)
err = validate.Struct(m)
suite.EqualError(err, "Key: 'MediaAttachment.Processing' Error:Field validation for 'Processing' failed on the 'oneof' tag")
}

View File

@ -49,7 +49,7 @@ type MentionValidateTestSuite struct {
func (suite *MentionValidateTestSuite) TestValidateMentionHappyPath() {
// no problem here
m := happyMention()
err := validate.Struct(*m)
err := validate.Struct(m)
suite.NoError(err)
}
@ -57,11 +57,11 @@ func (suite *MentionValidateTestSuite) TestValidateMentionBadID() {
m := happyMention()
m.ID = ""
err := validate.Struct(*m)
err := validate.Struct(m)
suite.EqualError(err, "Key: 'Mention.ID' Error:Field validation for 'ID' failed on the 'required' tag")
m.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB"
err = validate.Struct(*m)
err = validate.Struct(m)
suite.EqualError(err, "Key: 'Mention.ID' Error:Field validation for 'ID' failed on the 'ulid' tag")
}
@ -69,11 +69,11 @@ func (suite *MentionValidateTestSuite) TestValidateMentionAccountURI() {
m := happyMention()
m.OriginAccountURI = ""
err := validate.Struct(*m)
err := validate.Struct(m)
suite.EqualError(err, "Key: 'Mention.OriginAccountURI' Error:Field validation for 'OriginAccountURI' failed on the 'url' tag")
m.OriginAccountURI = "---------------------------"
err = validate.Struct(*m)
err = validate.Struct(m)
suite.EqualError(err, "Key: 'Mention.OriginAccountURI' Error:Field validation for 'OriginAccountURI' failed on the 'url' tag")
}
@ -81,11 +81,11 @@ func (suite *MentionValidateTestSuite) TestValidateMentionDodgyStatusID() {
m := happyMention()
m.StatusID = "9HZJ76B6VXSKF"
err := validate.Struct(*m)
err := validate.Struct(m)
suite.EqualError(err, "Key: 'Mention.StatusID' Error:Field validation for 'StatusID' failed on the 'ulid' tag")
m.StatusID = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!!!!!!!!!!!!"
err = validate.Struct(*m)
err = validate.Struct(m)
suite.EqualError(err, "Key: 'Mention.StatusID' Error:Field validation for 'StatusID' failed on the 'ulid' tag")
}
@ -93,7 +93,7 @@ func (suite *MentionValidateTestSuite) TestValidateMentionNoCreatedAt() {
m := happyMention()
m.CreatedAt = time.Time{}
err := validate.Struct(*m)
err := validate.Struct(m)
suite.NoError(err)
}

View File

@ -47,49 +47,49 @@ type NotificationValidateTestSuite struct {
func (suite *NotificationValidateTestSuite) TestValidateNotificationHappyPath() {
// no problem here
m := happyNotification()
err := validate.Struct(*m)
n := happyNotification()
err := validate.Struct(n)
suite.NoError(err)
}
func (suite *NotificationValidateTestSuite) TestValidateNotificationBadID() {
m := happyNotification()
n := happyNotification()
m.ID = ""
err := validate.Struct(*m)
n.ID = ""
err := validate.Struct(n)
suite.EqualError(err, "Key: 'Notification.ID' Error:Field validation for 'ID' failed on the 'required' tag")
m.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB"
err = validate.Struct(*m)
n.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB"
err = validate.Struct(n)
suite.EqualError(err, "Key: 'Notification.ID' Error:Field validation for 'ID' failed on the 'ulid' tag")
}
func (suite *NotificationValidateTestSuite) TestValidateNotificationStatusID() {
m := happyNotification()
n := happyNotification()
m.StatusID = ""
err := validate.Struct(*m)
n.StatusID = ""
err := validate.Struct(n)
suite.EqualError(err, "Key: 'Notification.StatusID' Error:Field validation for 'StatusID' failed on the 'required_if' tag")
m.StatusID = "9HZJ76B6VXSKF"
err = validate.Struct(*m)
n.StatusID = "9HZJ76B6VXSKF"
err = validate.Struct(n)
suite.EqualError(err, "Key: 'Notification.StatusID' Error:Field validation for 'StatusID' failed on the 'ulid' tag")
m.StatusID = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!!!!!!!!!!!!"
err = validate.Struct(*m)
n.StatusID = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!!!!!!!!!!!!"
err = validate.Struct(n)
suite.EqualError(err, "Key: 'Notification.StatusID' Error:Field validation for 'StatusID' failed on the 'ulid' tag")
m.StatusID = ""
m.NotificationType = gtsmodel.NotificationFollowRequest
err = validate.Struct(*m)
n.StatusID = ""
n.NotificationType = gtsmodel.NotificationFollowRequest
err = validate.Struct(n)
suite.NoError(err)
}
func (suite *NotificationValidateTestSuite) TestValidateNotificationNoCreatedAt() {
m := happyNotification()
n := happyNotification()
m.CreatedAt = time.Time{}
err := validate.Struct(*m)
n.CreatedAt = time.Time{}
err := validate.Struct(n)
suite.NoError(err)
}

View File

@ -41,7 +41,7 @@ type RouterSessionValidateTestSuite struct {
func (suite *RouterSessionValidateTestSuite) TestValidateRouterSessionHappyPath() {
// no problem here
r := happyRouterSession()
err := validate.Struct(*r)
err := validate.Struct(r)
suite.NoError(err)
}
@ -50,17 +50,17 @@ func (suite *RouterSessionValidateTestSuite) TestValidateRouterSessionAuth() {
// remove auth struct
r.Auth = nil
err := validate.Struct(*r)
err := validate.Struct(r)
suite.EqualError(err, "Key: 'RouterSession.Auth' Error:Field validation for 'Auth' failed on the 'required' tag")
// auth bytes too long
r.Auth = []byte("1234567890123456789012345678901234567890")
err = validate.Struct(*r)
err = validate.Struct(r)
suite.EqualError(err, "Key: 'RouterSession.Auth' Error:Field validation for 'Auth' failed on the 'len' tag")
// auth bytes too short
r.Auth = []byte("12345678901")
err = validate.Struct(*r)
err = validate.Struct(r)
suite.EqualError(err, "Key: 'RouterSession.Auth' Error:Field validation for 'Auth' failed on the 'len' tag")
}
@ -69,17 +69,17 @@ func (suite *RouterSessionValidateTestSuite) TestValidateRouterSessionCrypt() {
// remove crypt struct
r.Crypt = nil
err := validate.Struct(*r)
err := validate.Struct(r)
suite.EqualError(err, "Key: 'RouterSession.Crypt' Error:Field validation for 'Crypt' failed on the 'required' tag")
// crypt bytes too long
r.Crypt = []byte("1234567890123456789012345678901234567890")
err = validate.Struct(*r)
err = validate.Struct(r)
suite.EqualError(err, "Key: 'RouterSession.Crypt' Error:Field validation for 'Crypt' failed on the 'len' tag")
// crypt bytes too short
r.Crypt = []byte("12345678901")
err = validate.Struct(*r)
err = validate.Struct(r)
suite.EqualError(err, "Key: 'RouterSession.Crypt' Error:Field validation for 'Crypt' failed on the 'len' tag")
}

View File

@ -82,7 +82,7 @@ type StatusValidateTestSuite struct {
func (suite *StatusValidateTestSuite) TestValidateStatusHappyPath() {
// no problem here
s := happyStatus()
err := validate.Struct(*s)
err := validate.Struct(s)
suite.NoError(err)
}
@ -90,11 +90,11 @@ func (suite *StatusValidateTestSuite) TestValidateStatusBadID() {
s := happyStatus()
s.ID = ""
err := validate.Struct(*s)
err := validate.Struct(s)
suite.EqualError(err, "Key: 'Status.ID' Error:Field validation for 'ID' failed on the 'required' tag")
s.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB"
err = validate.Struct(*s)
err = validate.Struct(s)
suite.EqualError(err, "Key: 'Status.ID' Error:Field validation for 'ID' failed on the 'ulid' tag")
}
@ -102,23 +102,23 @@ func (suite *StatusValidateTestSuite) TestValidateStatusAttachmentIDs() {
s := happyStatus()
s.AttachmentIDs[0] = ""
err := validate.Struct(*s)
err := validate.Struct(s)
suite.EqualError(err, "Key: 'Status.AttachmentIDs[0]' Error:Field validation for 'AttachmentIDs[0]' failed on the 'ulid' tag")
s.AttachmentIDs[0] = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB"
err = validate.Struct(*s)
err = validate.Struct(s)
suite.EqualError(err, "Key: 'Status.AttachmentIDs[0]' Error:Field validation for 'AttachmentIDs[0]' failed on the 'ulid' tag")
s.AttachmentIDs[1] = ""
err = validate.Struct(*s)
err = validate.Struct(s)
suite.EqualError(err, "Key: 'Status.AttachmentIDs[0]' Error:Field validation for 'AttachmentIDs[0]' failed on the 'ulid' tag\nKey: 'Status.AttachmentIDs[1]' Error:Field validation for 'AttachmentIDs[1]' failed on the 'ulid' tag")
s.AttachmentIDs = []string{}
err = validate.Struct(*s)
err = validate.Struct(s)
suite.NoError(err)
s.AttachmentIDs = nil
err = validate.Struct(*s)
err = validate.Struct(s)
suite.NoError(err)
}
@ -126,11 +126,11 @@ func (suite *StatusValidateTestSuite) TestStatusApplicationID() {
s := happyStatus()
s.CreatedWithApplicationID = ""
err := validate.Struct(*s)
err := validate.Struct(s)
suite.EqualError(err, "Key: 'Status.CreatedWithApplicationID' Error:Field validation for 'CreatedWithApplicationID' failed on the 'required_if' tag")
s.Local = false
err = validate.Struct(*s)
err = validate.Struct(s)
suite.NoError(err)
}
@ -138,23 +138,23 @@ func (suite *StatusValidateTestSuite) TestValidateStatusReplyFields() {
s := happyStatus()
s.InReplyToAccountID = "01FEBCTP6DN7961PN81C3DVM4N "
err := validate.Struct(*s)
err := validate.Struct(s)
suite.EqualError(err, "Key: 'Status.InReplyToID' Error:Field validation for 'InReplyToID' failed on the 'required_with' tag\nKey: 'Status.InReplyToURI' Error:Field validation for 'InReplyToURI' failed on the 'required_with' tag\nKey: 'Status.InReplyToAccountID' Error:Field validation for 'InReplyToAccountID' failed on the 'ulid' tag")
s.InReplyToAccountID = "01FEBCTP6DN7961PN81C3DVM4N"
err = validate.Struct(*s)
err = validate.Struct(s)
suite.EqualError(err, "Key: 'Status.InReplyToID' Error:Field validation for 'InReplyToID' failed on the 'required_with' tag\nKey: 'Status.InReplyToURI' Error:Field validation for 'InReplyToURI' failed on the 'required_with' tag")
s.InReplyToURI = "https://example.org/users/mmbop/statuses/aaaaaaaa"
err = validate.Struct(*s)
err = validate.Struct(s)
suite.EqualError(err, "Key: 'Status.InReplyToID' Error:Field validation for 'InReplyToID' failed on the 'required_with' tag")
s.InReplyToID = "not a valid ulid"
err = validate.Struct(*s)
err = validate.Struct(s)
suite.EqualError(err, "Key: 'Status.InReplyToID' Error:Field validation for 'InReplyToID' failed on the 'ulid' tag")
s.InReplyToID = "01FEBD07E72DEY6YB9K10ZA6ST"
err = validate.Struct(*s)
err = validate.Struct(s)
suite.NoError(err)
}

View File

@ -46,40 +46,40 @@ type StatusBookmarkValidateTestSuite struct {
func (suite *StatusBookmarkValidateTestSuite) TestValidateStatusBookmarkHappyPath() {
// no problem here
m := happyStatusBookmark()
err := validate.Struct(*m)
s := happyStatusBookmark()
err := validate.Struct(s)
suite.NoError(err)
}
func (suite *StatusBookmarkValidateTestSuite) TestValidateStatusBookmarkBadID() {
m := happyStatusBookmark()
s := happyStatusBookmark()
m.ID = ""
err := validate.Struct(*m)
s.ID = ""
err := validate.Struct(s)
suite.EqualError(err, "Key: 'StatusBookmark.ID' Error:Field validation for 'ID' failed on the 'required' tag")
m.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB"
err = validate.Struct(*m)
s.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB"
err = validate.Struct(s)
suite.EqualError(err, "Key: 'StatusBookmark.ID' Error:Field validation for 'ID' failed on the 'ulid' tag")
}
func (suite *StatusBookmarkValidateTestSuite) TestValidateStatusBookmarkDodgyStatusID() {
m := happyStatusBookmark()
s := happyStatusBookmark()
m.StatusID = "9HZJ76B6VXSKF"
err := validate.Struct(*m)
s.StatusID = "9HZJ76B6VXSKF"
err := validate.Struct(s)
suite.EqualError(err, "Key: 'StatusBookmark.StatusID' Error:Field validation for 'StatusID' failed on the 'ulid' tag")
m.StatusID = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!!!!!!!!!!!!"
err = validate.Struct(*m)
s.StatusID = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!!!!!!!!!!!!"
err = validate.Struct(s)
suite.EqualError(err, "Key: 'StatusBookmark.StatusID' Error:Field validation for 'StatusID' failed on the 'ulid' tag")
}
func (suite *StatusBookmarkValidateTestSuite) TestValidateStatusBookmarkNoCreatedAt() {
m := happyStatusBookmark()
s := happyStatusBookmark()
m.CreatedAt = time.Time{}
err := validate.Struct(*m)
s.CreatedAt = time.Time{}
err := validate.Struct(s)
suite.NoError(err)
}

View File

@ -48,7 +48,7 @@ type StatusFaveValidateTestSuite struct {
func (suite *StatusFaveValidateTestSuite) TestValidateStatusFaveHappyPath() {
// no problem here
f := happyStatusFave()
err := validate.Struct(*f)
err := validate.Struct(f)
suite.NoError(err)
}
@ -56,11 +56,11 @@ func (suite *StatusFaveValidateTestSuite) TestValidateStatusFaveBadID() {
f := happyStatusFave()
f.ID = ""
err := validate.Struct(*f)
err := validate.Struct(f)
suite.EqualError(err, "Key: 'StatusFave.ID' Error:Field validation for 'ID' failed on the 'required' tag")
f.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB"
err = validate.Struct(*f)
err = validate.Struct(f)
suite.EqualError(err, "Key: 'StatusFave.ID' Error:Field validation for 'ID' failed on the 'ulid' tag")
}
@ -68,11 +68,11 @@ func (suite *StatusFaveValidateTestSuite) TestValidateStatusFaveDodgyStatusID()
f := happyStatusFave()
f.StatusID = "9HZJ76B6VXSKF"
err := validate.Struct(*f)
err := validate.Struct(f)
suite.EqualError(err, "Key: 'StatusFave.StatusID' Error:Field validation for 'StatusID' failed on the 'ulid' tag")
f.StatusID = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!!!!!!!!!!!!"
err = validate.Struct(*f)
err = validate.Struct(f)
suite.EqualError(err, "Key: 'StatusFave.StatusID' Error:Field validation for 'StatusID' failed on the 'ulid' tag")
}
@ -80,7 +80,7 @@ func (suite *StatusFaveValidateTestSuite) TestValidateStatusFaveNoCreatedAt() {
f := happyStatusFave()
f.CreatedAt = time.Time{}
err := validate.Struct(*f)
err := validate.Struct(f)
suite.NoError(err)
}
@ -88,11 +88,11 @@ func (suite *StatusFaveValidateTestSuite) TestValidateStatusFaveNoURI() {
f := happyStatusFave()
f.URI = ""
err := validate.Struct(*f)
err := validate.Struct(f)
suite.EqualError(err, "Key: 'StatusFave.URI' Error:Field validation for 'URI' failed on the 'required' tag")
f.URI = "this-is-not-a-valid-url"
err = validate.Struct(*f)
err = validate.Struct(f)
suite.EqualError(err, "Key: 'StatusFave.URI' Error:Field validation for 'URI' failed on the 'url' tag")
}

View File

@ -47,7 +47,7 @@ type StatusMuteValidateTestSuite struct {
func (suite *StatusMuteValidateTestSuite) TestValidateStatusMuteHappyPath() {
// no problem here
m := happyStatusMute()
err := validate.Struct(*m)
err := validate.Struct(m)
suite.NoError(err)
}
@ -55,11 +55,11 @@ func (suite *StatusMuteValidateTestSuite) TestValidateStatusMuteBadID() {
m := happyStatusMute()
m.ID = ""
err := validate.Struct(*m)
err := validate.Struct(m)
suite.EqualError(err, "Key: 'StatusMute.ID' Error:Field validation for 'ID' failed on the 'required' tag")
m.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB"
err = validate.Struct(*m)
err = validate.Struct(m)
suite.EqualError(err, "Key: 'StatusMute.ID' Error:Field validation for 'ID' failed on the 'ulid' tag")
}
@ -67,11 +67,11 @@ func (suite *StatusMuteValidateTestSuite) TestValidateStatusMuteDodgyStatusID()
m := happyStatusMute()
m.StatusID = "9HZJ76B6VXSKF"
err := validate.Struct(*m)
err := validate.Struct(m)
suite.EqualError(err, "Key: 'StatusMute.StatusID' Error:Field validation for 'StatusID' failed on the 'ulid' tag")
m.StatusID = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!!!!!!!!!!!!"
err = validate.Struct(*m)
err = validate.Struct(m)
suite.EqualError(err, "Key: 'StatusMute.StatusID' Error:Field validation for 'StatusID' failed on the 'ulid' tag")
}
@ -79,7 +79,7 @@ func (suite *StatusMuteValidateTestSuite) TestValidateStatusMuteNoCreatedAt() {
m := happyStatusMute()
m.CreatedAt = time.Time{}
err := validate.Struct(*m)
err := validate.Struct(m)
suite.NoError(err)
}

View File

@ -29,7 +29,6 @@ var v *validator.Validate
// Validation Panic messages
const (
PointerPanic = "validate function was passed pointer"
InvalidPanic = "validate function was passed invalid item"
)
@ -53,11 +52,9 @@ func init() {
// Struct validates the passed struct, returning validator.ValidationErrors if invalid, or nil if OK.
func Struct(s interface{}) error {
switch reflect.ValueOf(s).Kind() {
switch reflect.TypeOf(s).Kind() {
case reflect.Invalid:
panic(InvalidPanic)
case reflect.Ptr:
panic(PointerPanic)
}
err := v.Struct(s)

View File

@ -30,15 +30,21 @@ type ValidateTestSuite struct {
suite.Suite
}
func (suite *ValidateTestSuite) TestValidatePointer() {
func (suite *ValidateTestSuite) TestValidateNilPointer() {
var nilUser *gtsmodel.User
suite.PanicsWithValue(validate.PointerPanic, func() {
suite.Panics(func() {
validate.Struct(nilUser)
})
}
func (suite *ValidateTestSuite) TestValidatePointer() {
user := &gtsmodel.User{}
err := validate.Struct(user)
suite.EqualError(err, "Key: 'User.ID' Error:Field validation for 'ID' failed on the 'required' tag\nKey: 'User.AccountID' Error:Field validation for 'AccountID' failed on the 'required' tag\nKey: 'User.EncryptedPassword' Error:Field validation for 'EncryptedPassword' failed on the 'required' tag\nKey: 'User.UnconfirmedEmail' Error:Field validation for 'UnconfirmedEmail' failed on the 'required_without' tag")
}
func (suite *ValidateTestSuite) TestValidateNil() {
suite.PanicsWithValue(validate.InvalidPanic, func() {
suite.Panics(func() {
validate.Struct(nil)
})
}

View File

@ -48,7 +48,7 @@ type TagValidateTestSuite struct {
func (suite *TagValidateTestSuite) TestValidateTagHappyPath() {
// no problem here
t := happyTag()
err := validate.Struct(*t)
err := validate.Struct(t)
suite.NoError(err)
}
@ -56,7 +56,7 @@ func (suite *TagValidateTestSuite) TestValidateTagNoName() {
t := happyTag()
t.Name = ""
err := validate.Struct(*t)
err := validate.Struct(t)
suite.EqualError(err, "Key: 'Tag.Name' Error:Field validation for 'Name' failed on the 'required' tag")
}
@ -64,19 +64,19 @@ func (suite *TagValidateTestSuite) TestValidateTagBadURL() {
t := happyTag()
t.URL = ""
err := validate.Struct(*t)
err := validate.Struct(t)
suite.EqualError(err, "Key: 'Tag.URL' Error:Field validation for 'URL' failed on the 'required' tag")
t.URL = "no-schema.com"
err = validate.Struct(*t)
err = validate.Struct(t)
suite.EqualError(err, "Key: 'Tag.URL' Error:Field validation for 'URL' failed on the 'url' tag")
t.URL = "justastring"
err = validate.Struct(*t)
err = validate.Struct(t)
suite.EqualError(err, "Key: 'Tag.URL' Error:Field validation for 'URL' failed on the 'url' tag")
t.URL = "https://aaa\n\n\naaaaaaaa"
err = validate.Struct(*t)
err = validate.Struct(t)
suite.EqualError(err, "Key: 'Tag.URL' Error:Field validation for 'URL' failed on the 'url' tag")
}
@ -84,7 +84,7 @@ func (suite *TagValidateTestSuite) TestValidateTagNoFirstSeenFromAccountID() {
t := happyTag()
t.FirstSeenFromAccountID = ""
err := validate.Struct(*t)
err := validate.Struct(t)
suite.NoError(err)
}

View File

@ -45,53 +45,53 @@ type TokenValidateTestSuite struct {
func (suite *TokenValidateTestSuite) TestValidateTokenHappyPath() {
// no problem here
a := happyToken()
err := validate.Struct(*a)
t := happyToken()
err := validate.Struct(t)
suite.NoError(err)
}
func (suite *TokenValidateTestSuite) TestValidateTokenBadID() {
a := happyToken()
t := happyToken()
a.ID = ""
err := validate.Struct(*a)
t.ID = ""
err := validate.Struct(t)
suite.EqualError(err, "Key: 'Token.ID' Error:Field validation for 'ID' failed on the 'required' tag")
a.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB"
err = validate.Struct(*a)
t.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB"
err = validate.Struct(t)
suite.EqualError(err, "Key: 'Token.ID' Error:Field validation for 'ID' failed on the 'ulid' tag")
}
func (suite *TokenValidateTestSuite) TestValidateTokenNoCreatedAt() {
a := happyToken()
t := happyToken()
a.CreatedAt = time.Time{}
err := validate.Struct(*a)
t.CreatedAt = time.Time{}
err := validate.Struct(t)
suite.NoError(err)
}
func (suite *TokenValidateTestSuite) TestValidateTokenRedirectURI() {
a := happyToken()
t := happyToken()
a.RedirectURI = "invalid-uri"
err := validate.Struct(*a)
t.RedirectURI = "invalid-uri"
err := validate.Struct(t)
suite.EqualError(err, "Key: 'Token.RedirectURI' Error:Field validation for 'RedirectURI' failed on the 'uri' tag")
a.RedirectURI = ""
err = validate.Struct(*a)
t.RedirectURI = ""
err = validate.Struct(t)
suite.EqualError(err, "Key: 'Token.RedirectURI' Error:Field validation for 'RedirectURI' failed on the 'required' tag")
a.RedirectURI = "urn:ietf:wg:oauth:2.0:oob"
err = validate.Struct(*a)
t.RedirectURI = "urn:ietf:wg:oauth:2.0:oob"
err = validate.Struct(t)
suite.NoError(err)
}
func (suite *TokenValidateTestSuite) TestValidateTokenScope() {
a := happyToken()
t := happyToken()
a.Scope = ""
err := validate.Struct(*a)
suite.NoError(err)
t.Scope = ""
err := validate.Struct(t)
suite.EqualError(err, "Key: 'Token.Scope' Error:Field validation for 'Scope' failed on the 'required' tag")
}
func TestTokenValidateTestSuite(t *testing.T) {

View File

@ -68,7 +68,7 @@ type UserValidateTestSuite struct {
func (suite *UserValidateTestSuite) TestValidateUserHappyPath() {
// no problem here
u := happyUser()
err := validate.Struct(*u)
err := validate.Struct(u)
suite.NoError(err)
}
@ -77,7 +77,7 @@ func (suite *UserValidateTestSuite) TestValidateUserNoID() {
u := happyUser()
u.ID = ""
err := validate.Struct(*u)
err := validate.Struct(u)
suite.EqualError(err, "Key: 'User.ID' Error:Field validation for 'ID' failed on the 'required' tag")
}
@ -86,7 +86,7 @@ func (suite *UserValidateTestSuite) TestValidateUserNoEmail() {
u := happyUser()
u.Email = ""
err := validate.Struct(*u)
err := validate.Struct(u)
suite.EqualError(err, "Key: 'User.Email' Error:Field validation for 'Email' failed on the 'required_with' tag\nKey: 'User.UnconfirmedEmail' Error:Field validation for 'UnconfirmedEmail' failed on the 'required_without' tag")
}
@ -96,7 +96,7 @@ func (suite *UserValidateTestSuite) TestValidateUserOnlyUnconfirmedEmail() {
u.Email = ""
u.UnconfirmedEmail = "whatever@example.org"
err := validate.Struct(*u)
err := validate.Struct(u)
suite.EqualError(err, "Key: 'User.Email' Error:Field validation for 'Email' failed on the 'required_with' tag")
}
@ -107,7 +107,7 @@ func (suite *UserValidateTestSuite) TestValidateUserOnlyUnconfirmedEmailOK() {
u.UnconfirmedEmail = "whatever@example.org"
u.ConfirmedAt = time.Time{}
err := validate.Struct(*u)
err := validate.Struct(u)
suite.NoError(err)
}
@ -116,10 +116,19 @@ func (suite *UserValidateTestSuite) TestValidateUserNoConfirmedAt() {
u := happyUser()
u.ConfirmedAt = time.Time{}
err := validate.Struct(*u)
err := validate.Struct(u)
suite.EqualError(err, "Key: 'User.ConfirmedAt' Error:Field validation for 'ConfirmedAt' failed on the 'required_with' tag")
}
func (suite *UserValidateTestSuite) TestValidateUserUnlikelySignInCount() {
// user has Email but no ConfirmedAt
u := happyUser()
u.SignInCount = -69
err := validate.Struct(u)
suite.EqualError(err, "Key: 'User.SignInCount' Error:Field validation for 'SignInCount' failed on the 'min' tag")
}
func TestUserValidateTestSuite(t *testing.T) {
suite.Run(t, new(UserValidateTestSuite))
}