mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Migrate tests from "model/authorize_test.go" to use testify (#12606)
* refactor tests, move to testify tests * replace t.Fatal with require from testify
This commit is contained in:
committed by
Jesús Espino
parent
77dc6a9544
commit
94a77e2ddb
@@ -18,10 +18,7 @@ func TestAuthJson(t *testing.T) {
|
||||
|
||||
json := a1.ToJson()
|
||||
ra1 := AuthDataFromJson(strings.NewReader(json))
|
||||
|
||||
if a1.Code != ra1.Code {
|
||||
t.Fatal("codes didn't match")
|
||||
}
|
||||
require.Equal(t, a1.Code, ra1.Code, "codes didn't match")
|
||||
|
||||
a2 := AuthorizeRequest{}
|
||||
a2.ClientId = NewId()
|
||||
@@ -30,9 +27,7 @@ func TestAuthJson(t *testing.T) {
|
||||
json = a2.ToJson()
|
||||
ra2 := AuthorizeRequestFromJson(strings.NewReader(json))
|
||||
|
||||
if a2.ClientId != ra2.ClientId {
|
||||
t.Fatal("client ids didn't match")
|
||||
}
|
||||
require.Equal(t, a2.ClientId, ra2.ClientId, "client ids didn't match")
|
||||
}
|
||||
|
||||
func TestAuthPreSave(t *testing.T) {
|
||||
@@ -51,85 +46,59 @@ func TestAuthIsValid(t *testing.T) {
|
||||
require.NotNil(t, ad.IsValid())
|
||||
|
||||
ad.ClientId = NewRandomString(28)
|
||||
if err := ad.IsValid(); err == nil {
|
||||
t.Fatal("Should have failed Client Id")
|
||||
}
|
||||
require.NotNil(t, ad.IsValid(), "Should have failed Client Id")
|
||||
|
||||
ad.ClientId = NewId()
|
||||
require.NotNil(t, ad.IsValid())
|
||||
|
||||
ad.UserId = NewRandomString(28)
|
||||
if err := ad.IsValid(); err == nil {
|
||||
t.Fatal("Should have failed User Id")
|
||||
}
|
||||
require.NotNil(t, ad.IsValid(), "Should have failed User Id")
|
||||
|
||||
ad.UserId = NewId()
|
||||
require.NotNil(t, ad.IsValid())
|
||||
|
||||
ad.Code = NewRandomString(129)
|
||||
if err := ad.IsValid(); err == nil {
|
||||
t.Fatal("Should have failed Code to long")
|
||||
}
|
||||
require.NotNil(t, ad.IsValid(), "Should have failed Code to long")
|
||||
|
||||
ad.Code = ""
|
||||
if err := ad.IsValid(); err == nil {
|
||||
t.Fatal("Should have failed Code not set")
|
||||
}
|
||||
require.NotNil(t, ad.IsValid(), "Should have failed Code not set")
|
||||
|
||||
ad.Code = NewId()
|
||||
require.NotNil(t, ad.IsValid())
|
||||
|
||||
ad.ExpiresIn = 0
|
||||
if err := ad.IsValid(); err == nil {
|
||||
t.Fatal("Should have failed invalid ExpiresIn")
|
||||
}
|
||||
require.NotNil(t, ad.IsValid(), "Should have failed invalid ExpiresIn")
|
||||
|
||||
ad.ExpiresIn = 1
|
||||
require.NotNil(t, ad.IsValid())
|
||||
|
||||
ad.CreateAt = 0
|
||||
if err := ad.IsValid(); err == nil {
|
||||
t.Fatal("Should have failed Invalid Create At")
|
||||
}
|
||||
require.NotNil(t, ad.IsValid(), "Should have failed Invalid Create At")
|
||||
|
||||
ad.CreateAt = 1
|
||||
require.NotNil(t, ad.IsValid())
|
||||
|
||||
ad.State = NewRandomString(129)
|
||||
if err := ad.IsValid(); err == nil {
|
||||
t.Fatal("Should have failed invalid State")
|
||||
}
|
||||
require.NotNil(t, ad.IsValid(), "Should have failed invalid State")
|
||||
|
||||
ad.State = NewRandomString(128)
|
||||
if err := ad.IsValid(); err == nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.NotNil(t, ad.IsValid())
|
||||
|
||||
ad.Scope = NewRandomString(1025)
|
||||
if err := ad.IsValid(); err == nil {
|
||||
t.Fatal("Should have failed invalid Scope")
|
||||
}
|
||||
require.NotNil(t, ad.IsValid(), "Should have failed invalid Scope")
|
||||
|
||||
ad.Scope = NewRandomString(128)
|
||||
require.NotNil(t, ad.IsValid())
|
||||
|
||||
ad.RedirectUri = ""
|
||||
if err := ad.IsValid(); err == nil {
|
||||
t.Fatal("Should have failed Redirect URI not set")
|
||||
}
|
||||
require.NotNil(t, ad.IsValid(), "Should have failed Redirect URI not set")
|
||||
|
||||
ad.RedirectUri = NewRandomString(28)
|
||||
if err := ad.IsValid(); err == nil {
|
||||
t.Fatal("Should have failed invalid URL")
|
||||
}
|
||||
require.NotNil(t, ad.IsValid(), "Should have failed invalid URL")
|
||||
|
||||
ad.RedirectUri = NewRandomString(257)
|
||||
if err := ad.IsValid(); err == nil {
|
||||
t.Fatal("Should have failed invalid URL")
|
||||
}
|
||||
require.NotNil(t, ad.IsValid(), "Should have failed invalid URL")
|
||||
|
||||
ad.RedirectUri = "http://example.com"
|
||||
if err := ad.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Nil(t, ad.IsValid())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user