token_test.go 956 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package v1
  2. import (
  3. "context"
  4. "flag"
  5. "go-common/app/admin/live/live-admin/dao"
  6. "testing"
  7. "time"
  8. v1pb "go-common/app/admin/live/live-admin/api/http/v1"
  9. "go-common/app/admin/live/live-admin/conf"
  10. . "github.com/smartystreets/goconvey/convey"
  11. )
  12. var tokenSrv *TokenService
  13. func init() {
  14. flag.Set("conf", "../../cmd/test.toml")
  15. if err := conf.Init(); err != nil {
  16. panic(err)
  17. }
  18. tokenSrv = NewTokenService(conf.Conf, dao.New(conf.Conf))
  19. }
  20. func TestUploadToken(t *testing.T) {
  21. Convey("TestTokenService", t, func() {
  22. req := &v1pb.NewTokenReq{
  23. Bucket: "slive",
  24. Operator: "KC",
  25. }
  26. resp, err := tokenSrv.New(context.TODO(), req)
  27. So(err, ShouldBeNil)
  28. So(resp.Token, ShouldNotBeEmpty)
  29. ok := tokenSrv.dao.VerifyUploadToken(context.TODO(), resp.Token)
  30. So(ok, ShouldBeTrue)
  31. // Test token expiration.
  32. time.Sleep(time.Second * 11)
  33. ok = tokenSrv.dao.VerifyUploadToken(context.TODO(), resp.Token)
  34. So(ok, ShouldBeFalse)
  35. })
  36. }