access_test.go 642 B

1234567891011121314151617181920212223242526272829303132
  1. package huawei
  2. import (
  3. "testing"
  4. "time"
  5. . "github.com/smartystreets/goconvey/convey"
  6. )
  7. func Test_NewAccess(t *testing.T) {
  8. Convey("new access", t, func() {
  9. ac, err := NewAccess("10125085", "iejq6hn3ds3d4neq1m21v443lmbm31gs")
  10. if err != nil {
  11. t.Errorf("new access error(%v)", err)
  12. } else {
  13. t.Log(ac.Token, ac.Expire)
  14. }
  15. })
  16. }
  17. func Test_AccessExpire(t *testing.T) {
  18. Convey("access expire", t, func() {
  19. ac := Access{Expire: time.Now().Add(-8 * time.Hour).Unix()}
  20. if !ac.IsExpired() {
  21. t.Errorf("access should be expire")
  22. }
  23. ac.Expire -= 10
  24. if ac.IsExpired() {
  25. t.Error("access should not be expire")
  26. }
  27. })
  28. }