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() { switch t.GetTypeName() {
case string(ap.ActorPerson): case ap.ActorPerson:
p, ok := t.(vocab.ActivityStreamsPerson) p, ok := t.(vocab.ActivityStreamsPerson)
if !ok { if !ok {
return nil, errors.New("DereferenceAccountable: error resolving type as activitystreams person") return nil, errors.New("DereferenceAccountable: error resolving type as activitystreams person")
} }
return p, nil return p, nil
case string(ap.ActorApplication): case ap.ActorApplication:
p, ok := t.(vocab.ActivityStreamsApplication) p, ok := t.(vocab.ActivityStreamsApplication)
if !ok { if !ok {
return nil, errors.New("DereferenceAccountable: error resolving type as activitystreams application") return nil, errors.New("DereferenceAccountable: error resolving type as activitystreams application")
} }
return p, nil return p, nil
case string(ap.ActorService): case ap.ActorService:
p, ok := t.(vocab.ActivityStreamsService) p, ok := t.(vocab.ActivityStreamsService)
if !ok { if !ok {
return nil, errors.New("DereferenceAccountable: error resolving type as activitystreams service") 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() { switch iter.GetType().GetTypeName() {
// we have the whole object so we can figure out what we're accepting // we have the whole object so we can figure out what we're accepting
case string(ap.ActivityFollow): case ap.ActivityFollow:
// ACCEPT FOLLOW // ACCEPT FOLLOW
asFollow, ok := iter.GetType().(vocab.ActivityStreamsFollow) asFollow, ok := iter.GetType().(vocab.ActivityStreamsFollow)
if !ok { if !ok {

View file

@ -73,7 +73,7 @@ func (f *federatingDB) Undo(ctx context.Context, undo vocab.ActivityStreamsUndo)
continue continue
} }
switch iter.GetType().GetTypeName() { switch iter.GetType().GetTypeName() {
case string(ap.ActivityFollow): case ap.ActivityFollow:
// UNDO FOLLOW // UNDO FOLLOW
ASFollow, ok := iter.GetType().(vocab.ActivityStreamsFollow) ASFollow, ok := iter.GetType().(vocab.ActivityStreamsFollow)
if !ok { if !ok {
@ -102,11 +102,11 @@ func (f *federatingDB) Undo(ctx context.Context, undo vocab.ActivityStreamsUndo)
} }
l.Debug("follow undone") l.Debug("follow undone")
return nil return nil
case string(ap.ActivityLike): case ap.ActivityLike:
// UNDO LIKE // UNDO LIKE
case string(ap.ActivityAnnounce): case ap.ActivityAnnounce:
// UNDO BOOST/REBLOG/ANNOUNCE // UNDO BOOST/REBLOG/ANNOUNCE
case string(ap.ActivityBlock): case ap.ActivityBlock:
// UNDO BLOCK // UNDO BLOCK
ASBlock, ok := iter.GetType().(vocab.ActivityStreamsBlock) ASBlock, ok := iter.GetType().(vocab.ActivityStreamsBlock)
if !ok { 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') 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') 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 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 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 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 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 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 Code string `validate:"-" bun:",pk,nullzero,notnull,default:''"` // Code, if present
CodeChallenge string `validate:"-" bun:",nullzero"` // Code challenge, if code present CodeChallenge string `validate:"-" bun:",nullzero"` // Code challenge, if code present
CodeChallengeMethod string `validate:"-" bun:",nullzero"` // Code challenge method, 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 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? 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? 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?) 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? 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? 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() { func (suite *ApplicationValidateTestSuite) TestValidateApplicationHappyPath() {
// no problem here // no problem here
a := happyApplication() a := happyApplication()
err := validate.Struct(*a) err := validate.Struct(a)
suite.NoError(err) suite.NoError(err)
} }
@ -56,11 +56,11 @@ func (suite *ApplicationValidateTestSuite) TestValidateApplicationBadID() {
a := happyApplication() a := happyApplication()
a.ID = "" 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") suite.EqualError(err, "Key: 'Application.ID' Error:Field validation for 'ID' failed on the 'required' tag")
a.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB" 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") 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 := happyApplication()
a.CreatedAt = time.Time{} a.CreatedAt = time.Time{}
err := validate.Struct(*a) err := validate.Struct(a)
suite.NoError(err) suite.NoError(err)
} }
@ -76,7 +76,7 @@ func (suite *ApplicationValidateTestSuite) TestValidateApplicationName() {
a := happyApplication() a := happyApplication()
a.Name = "" 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") 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 := happyApplication()
a.Website = "invalid-website" 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") suite.EqualError(err, "Key: 'Application.Website' Error:Field validation for 'Website' failed on the 'url' tag")
a.Website = "" a.Website = ""
err = validate.Struct(*a) err = validate.Struct(a)
suite.NoError(err) suite.NoError(err)
} }
@ -96,15 +96,15 @@ func (suite *ApplicationValidateTestSuite) TestValidateApplicationRedirectURI()
a := happyApplication() a := happyApplication()
a.RedirectURI = "invalid-uri" 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") suite.EqualError(err, "Key: 'Application.RedirectURI' Error:Field validation for 'RedirectURI' failed on the 'uri' tag")
a.RedirectURI = "" 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") 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" a.RedirectURI = "urn:ietf:wg:oauth:2.0:oob"
err = validate.Struct(*a) err = validate.Struct(a)
suite.NoError(err) suite.NoError(err)
} }
@ -112,11 +112,11 @@ func (suite *ApplicationValidateTestSuite) TestValidateApplicationClientSecret()
a := happyApplication() a := happyApplication()
a.ClientSecret = "invalid-uuid" 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") suite.EqualError(err, "Key: 'Application.ClientSecret' Error:Field validation for 'ClientSecret' failed on the 'uuid' tag")
a.ClientSecret = "" 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") 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 := happyApplication()
a.Scopes = "" a.Scopes = ""
err := validate.Struct(*a) err := validate.Struct(a)
suite.NoError(err) suite.EqualError(err, "Key: 'Application.Scopes' Error:Field validation for 'Scopes' failed on the 'required' tag")
} }
func TestApplicationValidateTestSuite(t *testing.T) { func TestApplicationValidateTestSuite(t *testing.T) {

View file

@ -46,68 +46,68 @@ type BlockValidateTestSuite struct {
func (suite *BlockValidateTestSuite) TestValidateBlockHappyPath() { func (suite *BlockValidateTestSuite) TestValidateBlockHappyPath() {
// no problem here // no problem here
d := happyBlock() b := happyBlock()
err := validate.Struct(*d) err := validate.Struct(b)
suite.NoError(err) suite.NoError(err)
} }
func (suite *BlockValidateTestSuite) TestValidateBlockBadID() { func (suite *BlockValidateTestSuite) TestValidateBlockBadID() {
d := happyBlock() b := happyBlock()
d.ID = "" b.ID = ""
err := validate.Struct(*d) err := validate.Struct(b)
suite.EqualError(err, "Key: 'Block.ID' Error:Field validation for 'ID' failed on the 'required' tag") suite.EqualError(err, "Key: 'Block.ID' Error:Field validation for 'ID' failed on the 'required' tag")
d.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB" b.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB"
err = validate.Struct(*d) err = validate.Struct(b)
suite.EqualError(err, "Key: 'Block.ID' Error:Field validation for 'ID' failed on the 'ulid' tag") suite.EqualError(err, "Key: 'Block.ID' Error:Field validation for 'ID' failed on the 'ulid' tag")
} }
func (suite *BlockValidateTestSuite) TestValidateBlockNoCreatedAt() { func (suite *BlockValidateTestSuite) TestValidateBlockNoCreatedAt() {
d := happyBlock() b := happyBlock()
d.CreatedAt = time.Time{} b.CreatedAt = time.Time{}
err := validate.Struct(*d) err := validate.Struct(b)
suite.NoError(err) suite.NoError(err)
} }
func (suite *BlockValidateTestSuite) TestValidateBlockCreatedByAccountID() { func (suite *BlockValidateTestSuite) TestValidateBlockCreatedByAccountID() {
d := happyBlock() b := happyBlock()
d.AccountID = "" b.AccountID = ""
err := validate.Struct(*d) err := validate.Struct(b)
suite.EqualError(err, "Key: 'Block.AccountID' Error:Field validation for 'AccountID' failed on the 'required' tag") suite.EqualError(err, "Key: 'Block.AccountID' Error:Field validation for 'AccountID' failed on the 'required' tag")
d.AccountID = "this-is-not-a-valid-ulid" b.AccountID = "this-is-not-a-valid-ulid"
err = validate.Struct(*d) err = validate.Struct(b)
suite.EqualError(err, "Key: 'Block.AccountID' Error:Field validation for 'AccountID' failed on the 'ulid' tag") suite.EqualError(err, "Key: 'Block.AccountID' Error:Field validation for 'AccountID' failed on the 'ulid' tag")
} }
func (suite *BlockValidateTestSuite) TestValidateBlockTargetAccountID() { func (suite *BlockValidateTestSuite) TestValidateBlockTargetAccountID() {
d := happyBlock() b := happyBlock()
d.TargetAccountID = "invalid-ulid" b.TargetAccountID = "invalid-ulid"
err := validate.Struct(*d) err := validate.Struct(b)
suite.EqualError(err, "Key: 'Block.TargetAccountID' Error:Field validation for 'TargetAccountID' failed on the 'ulid' tag") suite.EqualError(err, "Key: 'Block.TargetAccountID' Error:Field validation for 'TargetAccountID' failed on the 'ulid' tag")
d.TargetAccountID = "01FEEDHX4G7EGHF5GD9E82Y51Q" b.TargetAccountID = "01FEEDHX4G7EGHF5GD9E82Y51Q"
err = validate.Struct(*d) err = validate.Struct(b)
suite.NoError(err) suite.NoError(err)
d.TargetAccountID = "" b.TargetAccountID = ""
err = validate.Struct(*d) err = validate.Struct(b)
suite.EqualError(err, "Key: 'Block.TargetAccountID' Error:Field validation for 'TargetAccountID' failed on the 'required' tag") suite.EqualError(err, "Key: 'Block.TargetAccountID' Error:Field validation for 'TargetAccountID' failed on the 'required' tag")
} }
func (suite *BlockValidateTestSuite) TestValidateBlockURI() { func (suite *BlockValidateTestSuite) TestValidateBlockURI() {
d := happyBlock() b := happyBlock()
d.URI = "invalid-uri" b.URI = "invalid-uri"
err := validate.Struct(*d) err := validate.Struct(b)
suite.EqualError(err, "Key: 'Block.URI' Error:Field validation for 'URI' failed on the 'url' tag") suite.EqualError(err, "Key: 'Block.URI' Error:Field validation for 'URI' failed on the 'url' tag")
d.URI = "" b.URI = ""
err = validate.Struct(*d) err = validate.Struct(b)
suite.EqualError(err, "Key: 'Block.URI' Error:Field validation for 'URI' failed on the 'required' tag") 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() { func (suite *ClientValidateTestSuite) TestValidateClientHappyPath() {
// no problem here // no problem here
c := happyClient() c := happyClient()
err := validate.Struct(*c) err := validate.Struct(c)
suite.NoError(err) suite.NoError(err)
} }
@ -53,11 +53,11 @@ func (suite *ClientValidateTestSuite) TestValidateClientBadID() {
c := happyClient() c := happyClient()
c.ID = "" 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") suite.EqualError(err, "Key: 'Client.ID' Error:Field validation for 'ID' failed on the 'required' tag")
c.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB" 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") 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 := happyClient()
c.CreatedAt = time.Time{} c.CreatedAt = time.Time{}
err := validate.Struct(*c) err := validate.Struct(c)
suite.NoError(err) suite.NoError(err)
} }
@ -73,27 +73,27 @@ func (suite *ClientValidateTestSuite) TestValidateClientDomain() {
c := happyClient() c := happyClient()
c.Domain = "invalid-uri" 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") suite.EqualError(err, "Key: 'Client.Domain' Error:Field validation for 'Domain' failed on the 'uri' tag")
c.Domain = "" 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") 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" c.Domain = "urn:ietf:wg:oauth:2.0:oob"
err = validate.Struct(*c) err = validate.Struct(c)
suite.NoError(err) suite.NoError(err)
} }
func (suite *ClientValidateTestSuite) TestValidateSecret() { func (suite *ClientValidateTestSuite) TestValidateSecret() {
a := happyClient() c := happyClient()
a.Secret = "invalid-uuid" c.Secret = "invalid-uuid"
err := validate.Struct(*a) err := validate.Struct(c)
suite.EqualError(err, "Key: 'Client.Secret' Error:Field validation for 'Secret' failed on the 'uuid' tag") suite.EqualError(err, "Key: 'Client.Secret' Error:Field validation for 'Secret' failed on the 'uuid' tag")
a.Secret = "" c.Secret = ""
err = validate.Struct(*a) err = validate.Struct(c)
suite.EqualError(err, "Key: 'Client.Secret' Error:Field validation for 'Secret' failed on the 'required' tag") 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() { func (suite *DomainBlockValidateTestSuite) TestValidateDomainBlockHappyPath() {
// no problem here // no problem here
d := happyDomainBlock() d := happyDomainBlock()
err := validate.Struct(*d) err := validate.Struct(d)
suite.NoError(err) suite.NoError(err)
} }
@ -56,11 +56,11 @@ func (suite *DomainBlockValidateTestSuite) TestValidateDomainBlockBadID() {
d := happyDomainBlock() d := happyDomainBlock()
d.ID = "" 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") suite.EqualError(err, "Key: 'DomainBlock.ID' Error:Field validation for 'ID' failed on the 'required' tag")
d.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB" 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") 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 := happyDomainBlock()
d.CreatedAt = time.Time{} d.CreatedAt = time.Time{}
err := validate.Struct(*d) err := validate.Struct(d)
suite.NoError(err) suite.NoError(err)
} }
@ -76,11 +76,11 @@ func (suite *DomainBlockValidateTestSuite) TestValidateDomainBlockBadDomain() {
d := happyDomainBlock() d := happyDomainBlock()
d.Domain = "" 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") suite.EqualError(err, "Key: 'DomainBlock.Domain' Error:Field validation for 'Domain' failed on the 'required' tag")
d.Domain = "this-is-not-a-valid-domain" 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") 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 := happyDomainBlock()
d.CreatedByAccountID = "" 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") suite.EqualError(err, "Key: 'DomainBlock.CreatedByAccountID' Error:Field validation for 'CreatedByAccountID' failed on the 'required' tag")
d.CreatedByAccountID = "this-is-not-a-valid-ulid" 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") 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.PrivateComment = ""
d.PublicComment = "" d.PublicComment = ""
err := validate.Struct(*d) err := validate.Struct(d)
suite.NoError(err) suite.NoError(err)
} }
@ -109,11 +109,11 @@ func (suite *DomainBlockValidateTestSuite) TestValidateDomainSubscriptionID() {
d := happyDomainBlock() d := happyDomainBlock()
d.SubscriptionID = "invalid-ulid" 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") suite.EqualError(err, "Key: 'DomainBlock.SubscriptionID' Error:Field validation for 'SubscriptionID' failed on the 'ulid' tag")
d.SubscriptionID = "01FEEDHX4G7EGHF5GD9E82Y51Q" d.SubscriptionID = "01FEEDHX4G7EGHF5GD9E82Y51Q"
err = validate.Struct(*d) err = validate.Struct(d)
suite.NoError(err) suite.NoError(err)
} }

View file

@ -44,7 +44,7 @@ type EmailDomainBlockValidateTestSuite struct {
func (suite *EmailDomainBlockValidateTestSuite) TestValidateEmailDomainBlockHappyPath() { func (suite *EmailDomainBlockValidateTestSuite) TestValidateEmailDomainBlockHappyPath() {
// no problem here // no problem here
e := happyEmailDomainBlock() e := happyEmailDomainBlock()
err := validate.Struct(*e) err := validate.Struct(e)
suite.NoError(err) suite.NoError(err)
} }
@ -52,11 +52,11 @@ func (suite *EmailDomainBlockValidateTestSuite) TestValidateEmailDomainBlockBadI
e := happyEmailDomainBlock() e := happyEmailDomainBlock()
e.ID = "" 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") suite.EqualError(err, "Key: 'EmailDomainBlock.ID' Error:Field validation for 'ID' failed on the 'required' tag")
e.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB" 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") 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 := happyEmailDomainBlock()
e.CreatedAt = time.Time{} e.CreatedAt = time.Time{}
err := validate.Struct(*e) err := validate.Struct(e)
suite.NoError(err) suite.NoError(err)
} }
@ -72,11 +72,11 @@ func (suite *EmailDomainBlockValidateTestSuite) TestValidateEmailDomainBlockBadD
e := happyEmailDomainBlock() e := happyEmailDomainBlock()
e.Domain = "" 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") suite.EqualError(err, "Key: 'EmailDomainBlock.Domain' Error:Field validation for 'Domain' failed on the 'required' tag")
e.Domain = "this-is-not-a-valid-domain" 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") 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 := happyEmailDomainBlock()
e.CreatedByAccountID = "" 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") suite.EqualError(err, "Key: 'EmailDomainBlock.CreatedByAccountID' Error:Field validation for 'CreatedByAccountID' failed on the 'required' tag")
e.CreatedByAccountID = "this-is-not-a-valid-ulid" 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") 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 := happyEmoji()
e.ImagePath = "/tmp/nonexistent/file/for/gotosocial/test" 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") suite.EqualError(err, "Key: 'Emoji.ImagePath' Error:Field validation for 'ImagePath' failed on the 'file' tag")
e.ImagePath = "" 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") suite.EqualError(err, "Key: 'Emoji.ImagePath' Error:Field validation for 'ImagePath' failed on the 'required' tag")
e.ImagePath = "???????????thisnot a valid path####" 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") suite.EqualError(err, "Key: 'Emoji.ImagePath' Error:Field validation for 'ImagePath' failed on the 'file' tag")
e.ImageStaticPath = "/tmp/nonexistent/file/for/gotosocial/test" 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") 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 = "" 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") 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####" 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") 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 := happyEmoji()
e.URI = "aaaaaaaaaa" 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") suite.EqualError(err, "Key: 'Emoji.URI' Error:Field validation for 'URI' failed on the 'url' tag")
e.URI = "" 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") 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 := happyEmoji()
e.ImageRemoteURL = "" 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") 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" e.ImageURL = "https://whatever.org"
err = validate.Struct(*e) err = validate.Struct(e)
suite.NoError(err) suite.NoError(err)
e.ImageStaticRemoteURL = "" 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") 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" e.ImageStaticURL = "https://whatever.org"
err = validate.Struct(*e) err = validate.Struct(e)
suite.NoError(err) suite.NoError(err)
e.ImageURL = "" e.ImageURL = ""
e.ImageStaticURL = "" e.ImageStaticURL = ""
e.ImageRemoteURL = "" e.ImageRemoteURL = ""
e.ImageStaticRemoteURL = "" 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") 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 := happyEmoji()
e.ImageFileSize = 0 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") suite.EqualError(err, "Key: 'Emoji.ImageFileSize' Error:Field validation for 'ImageFileSize' failed on the 'required' tag")
e.ImageStaticFileSize = 0 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") 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 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") 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 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") 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 := happyEmoji()
e.Domain = "" 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") 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" 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") 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() { func (suite *FollowValidateTestSuite) TestValidateFollowHappyPath() {
// no problem here // no problem here
f := happyFollow() f := happyFollow()
err := validate.Struct(*f) err := validate.Struct(f)
suite.NoError(err) suite.NoError(err)
} }
@ -55,11 +55,11 @@ func (suite *FollowValidateTestSuite) TestValidateFollowBadID() {
f := happyFollow() f := happyFollow()
f.ID = "" 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") suite.EqualError(err, "Key: 'Follow.ID' Error:Field validation for 'ID' failed on the 'required' tag")
f.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB" 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") 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 := happyFollow()
f.CreatedAt = time.Time{} f.CreatedAt = time.Time{}
err := validate.Struct(*f) err := validate.Struct(f)
suite.NoError(err) suite.NoError(err)
} }
@ -75,11 +75,11 @@ func (suite *FollowValidateTestSuite) TestValidateFollowNoURI() {
f := happyFollow() f := happyFollow()
f.URI = "" 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") suite.EqualError(err, "Key: 'Follow.URI' Error:Field validation for 'URI' failed on the 'required' tag")
f.URI = "this-is-not-a-valid-url" 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") 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() { func (suite *FollowRequestValidateTestSuite) TestValidateFollowRequestHappyPath() {
// no problem here // no problem here
f := happyFollowRequest() f := happyFollowRequest()
err := validate.Struct(*f) err := validate.Struct(f)
suite.NoError(err) suite.NoError(err)
} }
@ -55,11 +55,11 @@ func (suite *FollowRequestValidateTestSuite) TestValidateFollowRequestBadID() {
f := happyFollowRequest() f := happyFollowRequest()
f.ID = "" 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") suite.EqualError(err, "Key: 'FollowRequest.ID' Error:Field validation for 'ID' failed on the 'required' tag")
f.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB" 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") 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 := happyFollowRequest()
f.CreatedAt = time.Time{} f.CreatedAt = time.Time{}
err := validate.Struct(*f) err := validate.Struct(f)
suite.NoError(err) suite.NoError(err)
} }
@ -75,11 +75,11 @@ func (suite *FollowRequestValidateTestSuite) TestValidateFollowRequestNoURI() {
f := happyFollowRequest() f := happyFollowRequest()
f.URI = "" 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") suite.EqualError(err, "Key: 'FollowRequest.URI' Error:Field validation for 'URI' failed on the 'required' tag")
f.URI = "this-is-not-a-valid-url" 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") 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 := happyInstance()
i.URI = "" 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") suite.EqualError(err, "Key: 'Instance.URI' Error:Field validation for 'URI' failed on the 'required' tag")
i.URI = "---------------------------" 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") 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 := happyInstance()
i.ContactAccountID = "9HZJ76B6VXSKF" 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") suite.EqualError(err, "Key: 'Instance.ContactAccountID' Error:Field validation for 'ContactAccountID' failed on the 'ulid' tag")
i.ContactAccountID = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!!!!!!!!!!!!" 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") suite.EqualError(err, "Key: 'Instance.ContactAccountID' Error:Field validation for 'ContactAccountID' failed on the 'ulid' tag")
i.ContactAccountID = "" 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") suite.EqualError(err, "Key: 'Instance.ContactAccountID' Error:Field validation for 'ContactAccountID' failed on the 'required_with' tag")
i.ContactAccountUsername = "" i.ContactAccountUsername = ""
err = validate.Struct(*i) err = validate.Struct(i)
suite.NoError(err) suite.NoError(err)
} }
@ -109,15 +109,15 @@ func (suite *InstanceValidateTestSuite) TestValidateInstanceDomain() {
i := happyInstance() i := happyInstance()
i.Domain = "poopoo" 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") suite.EqualError(err, "Key: 'Instance.Domain' Error:Field validation for 'Domain' failed on the 'fqdn' tag")
i.Domain = "" 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") suite.EqualError(err, "Key: 'Instance.Domain' Error:Field validation for 'Domain' failed on the 'required' tag")
i.Domain = "https://aaaaaaaaaaaaah.org" 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") 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 := happyInstance()
i.ContactEmail = "poopoo" 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") suite.EqualError(err, "Key: 'Instance.ContactEmail' Error:Field validation for 'ContactEmail' failed on the 'email' tag")
i.ContactEmail = "" i.ContactEmail = ""
err = validate.Struct(*i) err = validate.Struct(i)
suite.NoError(err) suite.NoError(err)
} }
@ -137,7 +137,7 @@ func (suite *InstanceValidateTestSuite) TestValidateInstanceNoCreatedAt() {
i := happyInstance() i := happyInstance()
i.CreatedAt = time.Time{} i.CreatedAt = time.Time{}
err := validate.Struct(*i) err := validate.Struct(i)
suite.NoError(err) suite.NoError(err)
} }

View file

@ -109,7 +109,7 @@ type MediaAttachmentValidateTestSuite struct {
func (suite *MediaAttachmentValidateTestSuite) TestValidateMediaAttachmentHappyPath() { func (suite *MediaAttachmentValidateTestSuite) TestValidateMediaAttachmentHappyPath() {
// no problem here // no problem here
m := happyMediaAttachment() m := happyMediaAttachment()
err := validate.Struct(*m) err := validate.Struct(m)
suite.NoError(err) suite.NoError(err)
} }
@ -117,27 +117,27 @@ func (suite *MediaAttachmentValidateTestSuite) TestValidateMediaAttachmentBadFil
m := happyMediaAttachment() m := happyMediaAttachment()
m.File.Path = "/tmp/nonexistent/file/for/gotosocial/test" 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") suite.EqualError(err, "Key: 'MediaAttachment.File.Path' Error:Field validation for 'Path' failed on the 'file' tag")
m.File.Path = "" 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") suite.EqualError(err, "Key: 'MediaAttachment.File.Path' Error:Field validation for 'Path' failed on the 'required' tag")
m.File.Path = "???????????thisnot a valid path####" 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") 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" 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") 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 = "" 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") 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####" 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") 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 := happyMediaAttachment()
m.Type = "" 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") suite.EqualError(err, "Key: 'MediaAttachment.Type' Error:Field validation for 'Type' failed on the 'oneof' tag")
m.Type = "Not Supported" 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") 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 := happyMediaAttachment()
m.FileMeta.Original.Aspect = 0 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") suite.EqualError(err, "Key: 'MediaAttachment.FileMeta.Original.Aspect' Error:Field validation for 'Aspect' failed on the 'required_with' tag")
m.FileMeta.Original.Height = 0 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") 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{} m.FileMeta.Original = gtsmodel.Original{}
err = validate.Struct(*m) err = validate.Struct(m)
suite.NoError(err) suite.NoError(err)
m.FileMeta.Focus.X = 3.6 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") suite.EqualError(err, "Key: 'MediaAttachment.FileMeta.Focus.X' Error:Field validation for 'X' failed on the 'max' tag")
m.FileMeta.Focus.Y = -50 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") 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 := happyMediaAttachment()
m.URL = "aaaaaaaaaa" 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") suite.EqualError(err, "Key: 'MediaAttachment.URL' Error:Field validation for 'URL' failed on the 'url' tag")
m.URL = "" 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") 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" 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") suite.EqualError(err, "Key: 'MediaAttachment.RemoteURL' Error:Field validation for 'RemoteURL' failed on the 'url' tag")
m.RemoteURL = "https://a-valid-url.gay" m.RemoteURL = "https://a-valid-url.gay"
err = validate.Struct(*m) err = validate.Struct(m)
suite.NoError(err) suite.NoError(err)
} }
@ -201,15 +201,15 @@ func (suite *MediaAttachmentValidateTestSuite) TestValidateMediaAttachmentBlurha
m := happyMediaAttachment() m := happyMediaAttachment()
m.Blurhash = "" 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") suite.EqualError(err, "Key: 'MediaAttachment.Blurhash' Error:Field validation for 'Blurhash' failed on the 'required_if' tag")
m.Type = gtsmodel.FileTypeAudio m.Type = gtsmodel.FileTypeAudio
err = validate.Struct(*m) err = validate.Struct(m)
suite.NoError(err) suite.NoError(err)
m.Blurhash = "some_blurhash" m.Blurhash = "some_blurhash"
err = validate.Struct(*m) err = validate.Struct(m)
suite.NoError(err) suite.NoError(err)
} }
@ -217,11 +217,11 @@ func (suite *MediaAttachmentValidateTestSuite) TestValidateMediaAttachmentProces
m := happyMediaAttachment() m := happyMediaAttachment()
m.Processing = 420 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") suite.EqualError(err, "Key: 'MediaAttachment.Processing' Error:Field validation for 'Processing' failed on the 'oneof' tag")
m.Processing = -5 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") 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() { func (suite *MentionValidateTestSuite) TestValidateMentionHappyPath() {
// no problem here // no problem here
m := happyMention() m := happyMention()
err := validate.Struct(*m) err := validate.Struct(m)
suite.NoError(err) suite.NoError(err)
} }
@ -57,11 +57,11 @@ func (suite *MentionValidateTestSuite) TestValidateMentionBadID() {
m := happyMention() m := happyMention()
m.ID = "" 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") suite.EqualError(err, "Key: 'Mention.ID' Error:Field validation for 'ID' failed on the 'required' tag")
m.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB" 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") 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 := happyMention()
m.OriginAccountURI = "" 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") suite.EqualError(err, "Key: 'Mention.OriginAccountURI' Error:Field validation for 'OriginAccountURI' failed on the 'url' tag")
m.OriginAccountURI = "---------------------------" 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") 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 := happyMention()
m.StatusID = "9HZJ76B6VXSKF" 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") suite.EqualError(err, "Key: 'Mention.StatusID' Error:Field validation for 'StatusID' failed on the 'ulid' tag")
m.StatusID = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!!!!!!!!!!!!" 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") 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 := happyMention()
m.CreatedAt = time.Time{} m.CreatedAt = time.Time{}
err := validate.Struct(*m) err := validate.Struct(m)
suite.NoError(err) suite.NoError(err)
} }

View file

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

View file

@ -41,7 +41,7 @@ type RouterSessionValidateTestSuite struct {
func (suite *RouterSessionValidateTestSuite) TestValidateRouterSessionHappyPath() { func (suite *RouterSessionValidateTestSuite) TestValidateRouterSessionHappyPath() {
// no problem here // no problem here
r := happyRouterSession() r := happyRouterSession()
err := validate.Struct(*r) err := validate.Struct(r)
suite.NoError(err) suite.NoError(err)
} }
@ -50,17 +50,17 @@ func (suite *RouterSessionValidateTestSuite) TestValidateRouterSessionAuth() {
// remove auth struct // remove auth struct
r.Auth = nil 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") suite.EqualError(err, "Key: 'RouterSession.Auth' Error:Field validation for 'Auth' failed on the 'required' tag")
// auth bytes too long // auth bytes too long
r.Auth = []byte("1234567890123456789012345678901234567890") 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") suite.EqualError(err, "Key: 'RouterSession.Auth' Error:Field validation for 'Auth' failed on the 'len' tag")
// auth bytes too short // auth bytes too short
r.Auth = []byte("12345678901") 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") 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 // remove crypt struct
r.Crypt = nil 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") suite.EqualError(err, "Key: 'RouterSession.Crypt' Error:Field validation for 'Crypt' failed on the 'required' tag")
// crypt bytes too long // crypt bytes too long
r.Crypt = []byte("1234567890123456789012345678901234567890") 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") suite.EqualError(err, "Key: 'RouterSession.Crypt' Error:Field validation for 'Crypt' failed on the 'len' tag")
// crypt bytes too short // crypt bytes too short
r.Crypt = []byte("12345678901") 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") 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() { func (suite *StatusValidateTestSuite) TestValidateStatusHappyPath() {
// no problem here // no problem here
s := happyStatus() s := happyStatus()
err := validate.Struct(*s) err := validate.Struct(s)
suite.NoError(err) suite.NoError(err)
} }
@ -90,11 +90,11 @@ func (suite *StatusValidateTestSuite) TestValidateStatusBadID() {
s := happyStatus() s := happyStatus()
s.ID = "" 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") suite.EqualError(err, "Key: 'Status.ID' Error:Field validation for 'ID' failed on the 'required' tag")
s.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB" 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") 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 := happyStatus()
s.AttachmentIDs[0] = "" 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") suite.EqualError(err, "Key: 'Status.AttachmentIDs[0]' Error:Field validation for 'AttachmentIDs[0]' failed on the 'ulid' tag")
s.AttachmentIDs[0] = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB" 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") suite.EqualError(err, "Key: 'Status.AttachmentIDs[0]' Error:Field validation for 'AttachmentIDs[0]' failed on the 'ulid' tag")
s.AttachmentIDs[1] = "" 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") 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{} s.AttachmentIDs = []string{}
err = validate.Struct(*s) err = validate.Struct(s)
suite.NoError(err) suite.NoError(err)
s.AttachmentIDs = nil s.AttachmentIDs = nil
err = validate.Struct(*s) err = validate.Struct(s)
suite.NoError(err) suite.NoError(err)
} }
@ -126,11 +126,11 @@ func (suite *StatusValidateTestSuite) TestStatusApplicationID() {
s := happyStatus() s := happyStatus()
s.CreatedWithApplicationID = "" 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") suite.EqualError(err, "Key: 'Status.CreatedWithApplicationID' Error:Field validation for 'CreatedWithApplicationID' failed on the 'required_if' tag")
s.Local = false s.Local = false
err = validate.Struct(*s) err = validate.Struct(s)
suite.NoError(err) suite.NoError(err)
} }
@ -138,23 +138,23 @@ func (suite *StatusValidateTestSuite) TestValidateStatusReplyFields() {
s := happyStatus() s := happyStatus()
s.InReplyToAccountID = "01FEBCTP6DN7961PN81C3DVM4N " 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") 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" 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") 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" 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") suite.EqualError(err, "Key: 'Status.InReplyToID' Error:Field validation for 'InReplyToID' failed on the 'required_with' tag")
s.InReplyToID = "not a valid ulid" 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") suite.EqualError(err, "Key: 'Status.InReplyToID' Error:Field validation for 'InReplyToID' failed on the 'ulid' tag")
s.InReplyToID = "01FEBD07E72DEY6YB9K10ZA6ST" s.InReplyToID = "01FEBD07E72DEY6YB9K10ZA6ST"
err = validate.Struct(*s) err = validate.Struct(s)
suite.NoError(err) suite.NoError(err)
} }

View file

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

View file

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

View file

@ -29,7 +29,6 @@
// Validation Panic messages // Validation Panic messages
const ( const (
PointerPanic = "validate function was passed pointer"
InvalidPanic = "validate function was passed invalid item" 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. // Struct validates the passed struct, returning validator.ValidationErrors if invalid, or nil if OK.
func Struct(s interface{}) error { func Struct(s interface{}) error {
switch reflect.ValueOf(s).Kind() { switch reflect.TypeOf(s).Kind() {
case reflect.Invalid: case reflect.Invalid:
panic(InvalidPanic) panic(InvalidPanic)
case reflect.Ptr:
panic(PointerPanic)
} }
err := v.Struct(s) err := v.Struct(s)

View file

@ -30,15 +30,21 @@ type ValidateTestSuite struct {
suite.Suite suite.Suite
} }
func (suite *ValidateTestSuite) TestValidatePointer() { func (suite *ValidateTestSuite) TestValidateNilPointer() {
var nilUser *gtsmodel.User var nilUser *gtsmodel.User
suite.PanicsWithValue(validate.PointerPanic, func() { suite.Panics(func() {
validate.Struct(nilUser) 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() { func (suite *ValidateTestSuite) TestValidateNil() {
suite.PanicsWithValue(validate.InvalidPanic, func() { suite.Panics(func() {
validate.Struct(nil) validate.Struct(nil)
}) })
} }

View file

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

View file

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

View file

@ -68,7 +68,7 @@ type UserValidateTestSuite struct {
func (suite *UserValidateTestSuite) TestValidateUserHappyPath() { func (suite *UserValidateTestSuite) TestValidateUserHappyPath() {
// no problem here // no problem here
u := happyUser() u := happyUser()
err := validate.Struct(*u) err := validate.Struct(u)
suite.NoError(err) suite.NoError(err)
} }
@ -77,7 +77,7 @@ func (suite *UserValidateTestSuite) TestValidateUserNoID() {
u := happyUser() u := happyUser()
u.ID = "" 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") 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 := happyUser()
u.Email = "" 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") 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.Email = ""
u.UnconfirmedEmail = "whatever@example.org" 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") 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.UnconfirmedEmail = "whatever@example.org"
u.ConfirmedAt = time.Time{} u.ConfirmedAt = time.Time{}
err := validate.Struct(*u) err := validate.Struct(u)
suite.NoError(err) suite.NoError(err)
} }
@ -116,10 +116,19 @@ func (suite *UserValidateTestSuite) TestValidateUserNoConfirmedAt() {
u := happyUser() u := happyUser()
u.ConfirmedAt = time.Time{} 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") 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) { func TestUserValidateTestSuite(t *testing.T) {
suite.Run(t, new(UserValidateTestSuite)) suite.Run(t, new(UserValidateTestSuite))
} }