util_test.go 977 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. assert.Equal("6df41a43725f0c770fd56379e12acf8c", key)
  17. }
  18. func TestParseRangeNumbers(t *testing.T) {
  19. assert := assert.New(t)
  20. numbers, err := ParseRangeNumbers("2-5")
  21. if assert.NoError(err) {
  22. assert.Equal([]int64{2, 3, 4, 5}, numbers)
  23. }
  24. numbers, err = ParseRangeNumbers("1")
  25. if assert.NoError(err) {
  26. assert.Equal([]int64{1}, numbers)
  27. }
  28. numbers, err = ParseRangeNumbers("3-5,8")
  29. if assert.NoError(err) {
  30. assert.Equal([]int64{3, 4, 5, 8}, numbers)
  31. }
  32. numbers, err = ParseRangeNumbers(" 3-5,8, 10-12 ")
  33. if assert.NoError(err) {
  34. assert.Equal([]int64{3, 4, 5, 8, 10, 11, 12}, numbers)
  35. }
  36. _, err = ParseRangeNumbers("3-a")
  37. assert.Error(err)
  38. }