aboutsummaryrefslogtreecommitdiffstats
path: root/models/token_test.go
diff options
context:
space:
mode:
authorEthan Koenig <etk39@cornell.edu>2017-01-24 21:49:51 -0500
committerLunny Xiao <xiaolunwen@gmail.com>2017-01-25 10:49:51 +0800
commit8093b3372e812af6a5c3aab32559881011861243 (patch)
treed4a4ddcb947b2d35322849a2534543e2eb7dbb3e /models/token_test.go
parent75f0b0c51c1642551aebd83a1601187cfe89d172 (diff)
downloadgitea-8093b3372e812af6a5c3aab32559881011861243.tar.gz
gitea-8093b3372e812af6a5c3aab32559881011861243.zip
Less boilerplate in models/ unit tests (#725)
Diffstat (limited to 'models/token_test.go')
-rw-r--r--models/token_test.go22
1 files changed, 3 insertions, 19 deletions
diff --git a/models/token_test.go b/models/token_test.go
index 15207ceb65..9674be126a 100644
--- a/models/token_test.go
+++ b/models/token_test.go
@@ -17,13 +17,7 @@ func TestNewAccessToken(t *testing.T) {
Name: "Token C",
}
assert.NoError(t, NewAccessToken(token))
- sess := x.NewSession()
- defer sess.Close()
- has, err := sess.Get(*token)
- assert.NoError(t, err)
- assert.True(t, has)
- assert.Equal(t, int64(3), token.UID)
- assert.Equal(t, "Token C", token.Name)
+ AssertExistsAndLoadBean(t, token)
invalidToken := &AccessToken{
ID: token.ID, // duplicate
@@ -78,13 +72,7 @@ func TestUpdateAccessToken(t *testing.T) {
token.Name = "Token Z"
assert.NoError(t, UpdateAccessToken(token))
-
- sess := x.NewSession()
- defer sess.Close()
- has, err := sess.Get(token)
- assert.NoError(t, err)
- assert.True(t, has)
- assert.Equal(t, token.Name, "Token Z")
+ AssertExistsAndLoadBean(t, token)
}
func TestDeleteAccessTokenByID(t *testing.T) {
@@ -95,11 +83,7 @@ func TestDeleteAccessTokenByID(t *testing.T) {
assert.Equal(t, int64(1), token.UID)
assert.NoError(t, DeleteAccessTokenByID(token.ID, 1))
- sess := x.NewSession()
- defer sess.Close()
- has, err := sess.Get(token)
- assert.NoError(t, err)
- assert.False(t, has)
+ AssertNotExistsBean(t, token)
err = DeleteAccessTokenByID(100, 100)
assert.Error(t, err)