Modify: travis CI build and test
This commit is contained in:
parent
210af8f9e1
commit
83b292c9ba
4 changed files with 18 additions and 123 deletions
12
.travis.yml
12
.travis.yml
|
@ -5,12 +5,16 @@ git:
|
|||
depth: 1
|
||||
install:
|
||||
- go get github.com/rakyll/statik
|
||||
- sudo apt-get -y install gcc-mingw-w64-x86-64
|
||||
- sudo apt-get -y install gcc-arm-linux-gnueabihf libc6-dev-armhf-cross
|
||||
before_script:
|
||||
- statik -src=models -f
|
||||
- chmod +x ./build.sh
|
||||
script:
|
||||
- go test -coverprofile=coverage.txt -covermode=atomic ./...
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
before_deploy:
|
||||
- sudo apt-get -y install gcc-mingw-w64-x86-64
|
||||
- sudo apt-get -y install gcc-arm-linux-gnueabihf libc6-dev-armhf-cross
|
||||
- chmod +x ./build.sh
|
||||
- ./build.sh -r b
|
||||
deploy:
|
||||
provider: releases
|
||||
|
@ -19,6 +23,8 @@ deploy:
|
|||
file: release/*
|
||||
draft: true
|
||||
skip_cleanup: true
|
||||
on:
|
||||
tags: true
|
||||
# script:
|
||||
# - go test -coverprofile=coverage.txt -covermode=atomic ./...
|
||||
# after_success:
|
||||
|
|
|
@ -23,7 +23,7 @@ func TestGetGroupByID(t *testing.T) {
|
|||
ID: 1,
|
||||
},
|
||||
Name: "管理员",
|
||||
PolicyID: 1,
|
||||
Policies: "[1]",
|
||||
PolicyList: []uint{1},
|
||||
}, group)
|
||||
|
||||
|
@ -42,7 +42,7 @@ func TestGroup_AfterFind(t *testing.T) {
|
|||
ID: 1,
|
||||
},
|
||||
Name: "管理员",
|
||||
PolicyID: 1,
|
||||
Policies: "[1]",
|
||||
}
|
||||
err := testCase.AfterFind()
|
||||
asserts.NoError(err)
|
||||
|
|
|
@ -196,7 +196,6 @@ func TestShare_CanBeDownloadBy(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
share.Score = 1
|
||||
asserts.Error(share.CanBeDownloadBy(user))
|
||||
}
|
||||
|
||||
|
@ -210,7 +209,6 @@ func TestShare_CanBeDownloadBy(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
share.Score = 1
|
||||
asserts.NoError(share.CanBeDownloadBy(user))
|
||||
}
|
||||
}
|
||||
|
@ -260,66 +258,6 @@ func TestShare_DownloadBy(t *testing.T) {
|
|||
asserts.True(ok)
|
||||
}
|
||||
|
||||
func TestShare_Purchase(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
|
||||
// 不需要购买
|
||||
{
|
||||
share := Share{}
|
||||
user := User{}
|
||||
asserts.NoError(share.Purchase(&user))
|
||||
|
||||
share.Score = 1
|
||||
user.Group.OptionsSerialized.ShareFree = true
|
||||
asserts.NoError(share.Purchase(&user))
|
||||
|
||||
user.Group.OptionsSerialized.ShareFree = false
|
||||
share.UserID = 1
|
||||
user.ID = 1
|
||||
asserts.NoError(share.Purchase(&user))
|
||||
}
|
||||
|
||||
// 积分不足
|
||||
{
|
||||
share := Share{
|
||||
Score: 1,
|
||||
UserID: 2,
|
||||
}
|
||||
user := User{}
|
||||
asserts.Error(share.Purchase(&user))
|
||||
}
|
||||
|
||||
// 成功
|
||||
{
|
||||
cache.Set("setting_share_score_rate", "80", 0)
|
||||
share := Share{
|
||||
Score: 10,
|
||||
UserID: 2,
|
||||
User: User{
|
||||
Model: gorm.Model{
|
||||
ID: 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
user := User{
|
||||
Score: 10,
|
||||
}
|
||||
|
||||
mock.ExpectBegin()
|
||||
mock.ExpectExec("UPDATE(.+)").
|
||||
WillReturnResult(sqlmock.NewResult(1, 1))
|
||||
mock.ExpectCommit()
|
||||
mock.ExpectBegin()
|
||||
mock.ExpectExec("UPDATE(.+)").
|
||||
WillReturnResult(sqlmock.NewResult(1, 1))
|
||||
mock.ExpectCommit()
|
||||
asserts.NoError(share.Purchase(&user))
|
||||
asserts.NoError(mock.ExpectationsWereMet())
|
||||
asserts.EqualValues(0, user.Score)
|
||||
asserts.EqualValues(8, share.User.Score)
|
||||
}
|
||||
}
|
||||
|
||||
func TestShare_Viewed(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
share := Share{}
|
||||
|
|
|
@ -188,37 +188,15 @@ func TestUser_GetPolicyID(t *testing.T) {
|
|||
asserts := assert.New(t)
|
||||
|
||||
newUser := NewUser()
|
||||
newUser.Group.PolicyList = []uint{1}
|
||||
|
||||
testCases := []struct {
|
||||
preferred uint
|
||||
available []uint
|
||||
expected uint
|
||||
}{
|
||||
{
|
||||
available: []uint{1},
|
||||
expected: 1,
|
||||
},
|
||||
{
|
||||
available: []uint{5, 2, 3},
|
||||
expected: 5,
|
||||
},
|
||||
{
|
||||
preferred: 1,
|
||||
available: []uint{5, 1, 3},
|
||||
expected: 1,
|
||||
},
|
||||
{
|
||||
preferred: 9,
|
||||
available: []uint{5, 1, 3},
|
||||
expected: 5,
|
||||
},
|
||||
}
|
||||
asserts.EqualValues(1, newUser.GetPolicyID(0))
|
||||
|
||||
for key, testCase := range testCases {
|
||||
newUser.OptionsSerialized.PreferredPolicy = testCase.preferred
|
||||
newUser.Group.PolicyList = testCase.available
|
||||
asserts.Equal(testCase.expected, newUser.GetPolicyID(0), "测试用例 #%d 未通过", key)
|
||||
}
|
||||
newUser.Group.PolicyList = nil
|
||||
asserts.EqualValues(0, newUser.GetPolicyID(0))
|
||||
|
||||
newUser.Group.PolicyList = []uint{}
|
||||
asserts.EqualValues(0, newUser.GetPolicyID(0))
|
||||
}
|
||||
|
||||
func TestUser_GetRemainingCapacity(t *testing.T) {
|
||||
|
@ -395,33 +373,6 @@ func TestUser_Root(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestUser_PayScore(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
user := User{Score: 5}
|
||||
|
||||
asserts.True(user.PayScore(0))
|
||||
asserts.False(user.PayScore(10))
|
||||
|
||||
mock.ExpectBegin()
|
||||
mock.ExpectExec("UPDATE(.+)").WillReturnResult(sqlmock.NewResult(1, 1))
|
||||
mock.ExpectCommit()
|
||||
asserts.True(user.PayScore(5))
|
||||
asserts.EqualValues(0, user.Score)
|
||||
asserts.NoError(mock.ExpectationsWereMet())
|
||||
}
|
||||
|
||||
func TestUser_AddScore(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
user := User{Score: 5}
|
||||
|
||||
mock.ExpectBegin()
|
||||
mock.ExpectExec("UPDATE(.+)").WillReturnResult(sqlmock.NewResult(1, 1))
|
||||
mock.ExpectCommit()
|
||||
user.AddScore(5)
|
||||
asserts.NoError(mock.ExpectationsWereMet())
|
||||
asserts.EqualValues(10, user.Score)
|
||||
}
|
||||
|
||||
func TestNewAnonymousUser(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
|
||||
|
|
Loading…
Reference in a new issue