Test: hash id generate
This commit is contained in:
parent
0ee0ac5e89
commit
880d224169
2 changed files with 34 additions and 1 deletions
32
pkg/hashid/hash_test.go
Normal file
32
pkg/hashid/hash_test.go
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
package hashid
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestHashEncode(t *testing.T) {
|
||||||
|
asserts := assert.New(t)
|
||||||
|
|
||||||
|
{
|
||||||
|
res, err := HashEncode([]int{1, 2, 3})
|
||||||
|
asserts.NoError(err)
|
||||||
|
asserts.NotEmpty(res)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
res, err := HashEncode([]int{})
|
||||||
|
asserts.Error(err)
|
||||||
|
asserts.Empty(res)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHashID(t *testing.T) {
|
||||||
|
asserts := assert.New(t)
|
||||||
|
|
||||||
|
{
|
||||||
|
res := HashID(1, ShareID)
|
||||||
|
asserts.NotEmpty(res)
|
||||||
|
}
|
||||||
|
}
|
|
@ -51,7 +51,7 @@ func (service *ShareCreateService) Create(c *gin.Context) serializer.Response {
|
||||||
IsDir: service.IsDir,
|
IsDir: service.IsDir,
|
||||||
UserID: user.ID,
|
UserID: user.ID,
|
||||||
SourceID: service.SourceID,
|
SourceID: service.SourceID,
|
||||||
Score: service.RemainDownloads,
|
Score: service.Score,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果开启了自动过期
|
// 如果开启了自动过期
|
||||||
|
@ -78,4 +78,5 @@ func (service *ShareCreateService) Create(c *gin.Context) serializer.Response {
|
||||||
Code: 0,
|
Code: 0,
|
||||||
Data: shareURL.String(),
|
Data: shareURL.String(),
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue