func RabbitWithName(name string) (*RabbitMQ, error) { svc, err := env.ServiceWithName(name) if err != nil { return nil, err } return rabbitLift(svc) }
func EurekaWithName(name string) (*eureka.Client, error) { svc, err := env.ServiceWithName(name) if err != nil { return nil, err } return eurekaLift(svc) }
func svcHandler(rw http.ResponseWriter, req *http.Request) { name := mux.Vars(req)["name"] if name == "" { fmt.Fprint(rw, "Missing service name") rw.WriteHeader(http.StatusBadRequest) return } svc, err := env.ServiceWithName(name) if err != nil { fmt.Fprint(rw, err.Error()) rw.WriteHeader(http.StatusNotFound) return } out, err := json.Marshal(svc) if err != nil { fmt.Fprint(rw, err.Error()) rw.WriteHeader(http.StatusInternalServerError) return } fmt.Fprint(rw, string(out)) }
}) }) }) var _ = Describe(".ServiceWithName", func() { BeforeEach(func() { os.Setenv("VCAP_SERVICES", vcapServices) }) AfterEach(func() { os.Unsetenv("VCAP_SERVICES") }) Context("when the service is defined", func() { It("does NOT return an error", func() { _, err := env.ServiceWithName("service-name-2") Expect(err).ToNot(HaveOccurred()) }) It("returns the correct service", func() { svc, _ := env.ServiceWithName("service-name-2") Expect(svc.Name).To(Equal("service-name-2")) Expect(svc.Label).To(Equal("service-label")) Expect(svc.Plan).To(Equal("service-plan-2")) }) It("is case-insensitive", func() { _, err := env.ServiceWithName("SERVICE-NAME-2") Expect(err).ToNot(HaveOccurred()) }) })