pubsub_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2014 Google Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package pubsub
  15. import (
  16. "net/http"
  17. "strings"
  18. "testing"
  19. "time"
  20. "google.golang.org/cloud"
  21. )
  22. func TestIsSec(t *testing.T) {
  23. tests := map[time.Duration]bool{
  24. time.Second: true,
  25. 5 * time.Second: true,
  26. time.Hour: true,
  27. time.Millisecond: false,
  28. time.Second + time.Microsecond: false,
  29. }
  30. for dur, expected := range tests {
  31. if isSec(dur) != expected {
  32. t.Errorf("%v is more precise than a second", dur)
  33. }
  34. }
  35. }
  36. func TestEmptyAckID(t *testing.T) {
  37. ctx := cloud.NewContext("project-id", &http.Client{})
  38. id := []string{"test", ""}
  39. err := Ack(ctx, "sub", id...)
  40. if err == nil || !strings.Contains(err.Error(), "index 1") {
  41. t.Errorf("Ack should report an error indicating the id is empty. Got: %v", err)
  42. }
  43. }