1
0

util_test.go 989 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package util
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func TestRandId(t *testing.T) {
  7. assert := assert.New(t)
  8. id, err := RandId()
  9. assert.NoError(err)
  10. t.Log(id)
  11. assert.Equal(16, len(id))
  12. }
  13. func TestGetAuthKey(t *testing.T) {
  14. assert := assert.New(t)
  15. key := GetAuthKey("1234", 1488720000)
  16. t.Log(key)
  17. assert.Equal("6df41a43725f0c770fd56379e12acf8c", key)
  18. }
  19. func TestParseRangeNumbers(t *testing.T) {
  20. assert := assert.New(t)
  21. numbers, err := ParseRangeNumbers("2-5")
  22. if assert.NoError(err) {
  23. assert.Equal([]int64{2, 3, 4, 5}, numbers)
  24. }
  25. numbers, err = ParseRangeNumbers("1")
  26. if assert.NoError(err) {
  27. assert.Equal([]int64{1}, numbers)
  28. }
  29. numbers, err = ParseRangeNumbers("3-5,8")
  30. if assert.NoError(err) {
  31. assert.Equal([]int64{3, 4, 5, 8}, numbers)
  32. }
  33. numbers, err = ParseRangeNumbers(" 3-5,8, 10-12 ")
  34. if assert.NoError(err) {
  35. assert.Equal([]int64{3, 4, 5, 8, 10, 11, 12}, numbers)
  36. }
  37. _, err = ParseRangeNumbers("3-a")
  38. assert.Error(err)
  39. }