Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
394 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved. | ||
// See License.txt for license information. | ||
|
||
package model | ||
|
||
import ( | ||
"runtime/debug" | ||
"testing" | ||
) | ||
|
||
func CheckInt(t *testing.T, got int, expected int) { | ||
if got != expected { | ||
debug.PrintStack() | ||
t.Fatalf("Got: %v, Expected: %v", got, expected) | ||
} | ||
} | ||
|
||
func CheckInt64(t *testing.T, got int64, expected int64) { | ||
if got != expected { | ||
debug.PrintStack() | ||
t.Fatalf("Got: %v, Expected: %v", got, expected) | ||
} | ||
} | ||
|
||
func CheckString(t *testing.T, got string, expected string) { | ||
if got != expected { | ||
debug.PrintStack() | ||
t.Fatalf("Got: %v, Expected: %v", got, expected) | ||
} | ||
} | ||
|
||
func CheckTrue(t *testing.T, test bool) { | ||
if !test { | ||
debug.PrintStack() | ||
t.Fatal("Expected true") | ||
} | ||
} | ||
|
||
func CheckFalse(t *testing.T, test bool) { | ||
if test { | ||
debug.PrintStack() | ||
t.Fatal("Expected true") | ||
} | ||
} | ||
|
||
func CheckBool(t *testing.T, got bool, expected bool) { | ||
if got != expected { | ||
debug.PrintStack() | ||
t.Fatalf("Got: %v, Expected: %v", got, expected) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved. | ||
// See License.txt for license information. | ||
|
||
package model | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestPasswordRecoveryIsValid(t *testing.T) { | ||
// Valid example. | ||
p := PasswordRecovery{ | ||
UserId: NewId(), | ||
Code: strings.Repeat("a", 128), | ||
CreateAt: GetMillis(), | ||
} | ||
|
||
if err := p.IsValid(); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Various invalid ones. | ||
p.UserId = "abc" | ||
if err := p.IsValid(); err == nil { | ||
t.Fatal("Should have failed validation") | ||
} | ||
|
||
p.UserId = NewId() | ||
p.Code = "abc" | ||
if err := p.IsValid(); err == nil { | ||
t.Fatal("Should have failed validation") | ||
} | ||
|
||
p.Code = strings.Repeat("a", 128) | ||
p.CreateAt = 0 | ||
if err := p.IsValid(); err == nil { | ||
t.Fatal("Should have failed validation") | ||
} | ||
} | ||
|
||
func TestPasswordRecoveryPreSave(t *testing.T) { | ||
p := PasswordRecovery{ | ||
UserId: NewId(), | ||
} | ||
|
||
// Check it's valid after running PreSave | ||
p.PreSave() | ||
|
||
if err := p.IsValid(); err != nil { | ||
t.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved. | ||
// See License.txt for license information. | ||
|
||
package model | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestNewOkPushResponse(t *testing.T) { | ||
r := NewOkPushResponse() | ||
CheckString(t, r["status"], "OK") | ||
} | ||
|
||
func TestNewRemovePushResponse(t *testing.T) { | ||
r := NewRemovePushResponse() | ||
CheckString(t, r["status"], "REMOVE") | ||
} | ||
|
||
func TestNewErrorPushResponse(t *testing.T) { | ||
r := NewErrorPushResponse("error message") | ||
CheckString(t, r["status"], "FAIL") | ||
CheckString(t, r["error"], "error message") | ||
} | ||
|
||
func TestPushResponseToFromJson(t *testing.T) { | ||
r := NewErrorPushResponse("error message") | ||
j := r.ToJson() | ||
r1 := PushResponseFromJson(strings.NewReader(j)) | ||
|
||
CheckString(t, r1["status"], r["status"]) | ||
CheckString(t, r1["error"], r["error"]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved. | ||
// See License.txt for license information. | ||
|
||
package model | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestSecurityBulletinToFromJson(t *testing.T) { | ||
b := SecurityBulletin{ | ||
Id: NewId(), | ||
AppliesToVersion: NewId(), | ||
} | ||
|
||
j := b.ToJson() | ||
b1 := SecurityBulletinFromJson(strings.NewReader(j)) | ||
|
||
CheckString(t, b1.AppliesToVersion, b.AppliesToVersion) | ||
CheckString(t, b1.Id, b.Id) | ||
|
||
// Malformed JSON | ||
s2 := `{"wat"` | ||
b2 := SecurityBulletinFromJson(strings.NewReader(s2)) | ||
|
||
if b2 != nil { | ||
t.Fatal("expected nil") | ||
} | ||
} | ||
|
||
func TestSecurityBulletinsToFromJson(t *testing.T) { | ||
b := SecurityBulletins{ | ||
{ | ||
Id: NewId(), | ||
AppliesToVersion: NewId(), | ||
}, | ||
{ | ||
Id: NewId(), | ||
AppliesToVersion: NewId(), | ||
}, | ||
} | ||
|
||
j := b.ToJson() | ||
|
||
b1 := SecurityBulletinsFromJson(strings.NewReader(j)) | ||
|
||
CheckInt(t, len(b1), 2) | ||
|
||
// Malformed JSON | ||
s2 := `{"wat"` | ||
b2 := SecurityBulletinsFromJson(strings.NewReader(s2)) | ||
|
||
CheckInt(t, len(b2), 0) | ||
} |
Oops, something went wrong.