tokens_test.go 575 B

1234567891011121314151617181920212223242526272829
  1. package snowflake_proxy
  2. import (
  3. "testing"
  4. . "github.com/smartystreets/goconvey/convey"
  5. )
  6. func TestTokens(t *testing.T) {
  7. Convey("Tokens", t, func() {
  8. tokens := newTokens(2)
  9. So(tokens.count(), ShouldEqual, 0)
  10. tokens.get()
  11. So(tokens.count(), ShouldEqual, 1)
  12. tokens.ret()
  13. So(tokens.count(), ShouldEqual, 0)
  14. })
  15. Convey("Tokens capacity 0", t, func() {
  16. tokens := newTokens(0)
  17. So(tokens.count(), ShouldEqual, 0)
  18. for i := 0; i < 20; i++ {
  19. tokens.get()
  20. }
  21. So(tokens.count(), ShouldEqual, 20)
  22. tokens.ret()
  23. So(tokens.count(), ShouldEqual, 19)
  24. })
  25. }