/data/test/go/ffc32b5553d81c9692050eef7206cdff7e7d7c58redis_broker_suite_test.go

https://github.com/aliostad/deep-learning-lang-detection · Go · 143 lines · 123 code · 20 blank · 0 comment · 3 complexity · 39a5ac657354e4a33150b3afaa3eb0d7 MD5 · raw file

  1. package broker_test
  2. import (
  3. "strconv"
  4. "github.com/benchapman/redis-broker/broker"
  5. . "github.com/onsi/ginkgo"
  6. . "github.com/onsi/gomega"
  7. "github.com/pivotal-cf/brokerapi"
  8. "testing"
  9. )
  10. var _ = Describe(".RedisService", func() {
  11. var (
  12. redisBroker broker.RedisService
  13. )
  14. JustBeforeEach(func() {
  15. redisBroker = broker.New(broker.DatabaseIDs{}, "0.0.0.0")
  16. })
  17. Describe(".Services", func() {
  18. It("works", func() {
  19. Expect(redisBroker.Services()[0].Name).To(Equal("Shared Redis"))
  20. })
  21. })
  22. Describe(".Provision", func() {
  23. Context("if there are databases available", func() {
  24. It("should return a nil error", func() {
  25. _, err := redisBroker.Provision(
  26. "Pikachu",
  27. brokerapi.ProvisionDetails{},
  28. false,
  29. )
  30. Expect(err).To(BeNil())
  31. })
  32. })
  33. Context("if there are no databases available", func() {
  34. JustBeforeEach(func() {
  35. var fullArray broker.DatabaseIDs
  36. for i := range fullArray {
  37. fullArray[i] = strconv.Itoa(i)
  38. }
  39. redisBroker = broker.New(fullArray, "0.0.0.0")
  40. })
  41. It("should return an error if it can't provision a redis db", func() {
  42. _, err := redisBroker.Provision(
  43. "Pikachu",
  44. brokerapi.ProvisionDetails{},
  45. false,
  46. )
  47. Expect(err).ToNot(BeNil())
  48. })
  49. })
  50. })
  51. Describe(".Deprovision", func() {
  52. Context("when a service does not exist", func() {
  53. It("should return an error", func() {
  54. _, err := redisBroker.Deprovision(
  55. "Pikachu",
  56. brokerapi.DeprovisionDetails{},
  57. false,
  58. )
  59. Expect(err).ToNot(BeNil())
  60. })
  61. })
  62. Context("given a service has been provisioned", func() {
  63. JustBeforeEach(func() {
  64. redisBroker = broker.New(broker.DatabaseIDs{"Pikachu"}, "0.0.0.0")
  65. })
  66. It("should return no error", func() {
  67. _, err := redisBroker.Deprovision(
  68. "Pikachu",
  69. brokerapi.DeprovisionDetails{},
  70. false,
  71. )
  72. Expect(err).To(BeNil())
  73. })
  74. })
  75. })
  76. Describe(".Bind", func() {
  77. Context("given a service has been provisioned", func() {
  78. JustBeforeEach(func() {
  79. redisBroker.Provision("Pikachu", brokerapi.ProvisionDetails{}, false)
  80. })
  81. It("should return no errors when sucessfully bound", func() {
  82. _, err := redisBroker.Bind("Pikachu", "test", brokerapi.BindDetails{})
  83. Expect(err).To(BeNil())
  84. })
  85. It("should return a binding when successfully bound", func() {
  86. binding, err := redisBroker.Bind("Pikachu", "test", brokerapi.BindDetails{})
  87. Expect(err).To(BeNil())
  88. if credentials, ok := binding.Credentials.(broker.Credentials); ok {
  89. Expect(credentials.Database).To(Equal(1))
  90. } else {
  91. Fail("Could not cast to Credentials object.")
  92. }
  93. })
  94. })
  95. })
  96. })
  97. var _ = Describe("Functional test", func() {
  98. It("should provision and then deprovision", func() {
  99. redisBroker := broker.New(broker.DatabaseIDs{}, "0.0.0.0")
  100. _, err := redisBroker.Provision(
  101. "Pikachu",
  102. brokerapi.ProvisionDetails{},
  103. false,
  104. )
  105. Expect(err).To(BeNil())
  106. _, err = redisBroker.Deprovision(
  107. "Pikachu",
  108. brokerapi.DeprovisionDetails{},
  109. false,
  110. )
  111. Expect(err).To(BeNil())
  112. _, err = redisBroker.Deprovision(
  113. "Pikachu",
  114. brokerapi.DeprovisionDetails{},
  115. false,
  116. )
  117. Expect(err).ToNot(BeNil())
  118. })
  119. })
  120. func TestRedisBroker(t *testing.T) {
  121. RegisterFailHandler(Fail)
  122. RunSpecs(t, "RedisBroker Suite")
  123. }