func (db *serviceClient) Cells(logger lager.Logger) (models.CellSet, error) { kvPairs, _, err := db.consulClient.KV().List(CellSchemaRoot(), nil) if err != nil { bbsErr := models.ConvertError(convertConsulError(err)) if bbsErr.Type != models.Error_ResourceNotFound { return nil, bbsErr } } if kvPairs == nil { err = consuladapter.NewPrefixNotFoundError(CellSchemaRoot()) bbsErr := models.ConvertError(convertConsulError(err)) if bbsErr.Type != models.Error_ResourceNotFound { return nil, bbsErr } } cellPresences := models.NewCellSet() for _, kvPair := range kvPairs { if kvPair.Session == "" { continue } cell := kvPair.Value presence := new(models.CellPresence) err := models.FromJSON(cell, presence) if err != nil { logger.Error("failed-to-unmarshal-cells-json", err) continue } cellPresences.Add(presence) } return cellPresences, nil }
}) It("eventually returns no data", func() { otherAdapter := clusterRunner.NewSession("otherSession") Eventually(func() map[string][]byte { pairs, err := otherAdapter.ListAcquiredValues("under") Expect(err).NotTo(HaveOccurred()) return pairs }).Should(Equal(map[string][]byte{})) }) }) Context("when no keys are present", func() { It("returns an empty set", func() { _, err := session.ListAcquiredValues("not-present") Expect(err).To(Equal(consuladapter.NewPrefixNotFoundError("not-present"))) }) Context("when the prefix is present", func() { BeforeEach(func() { _, err := client.KV().Put(&api.KVPair{Key: unowned, Value: []byte{}}, nil) Expect(err).NotTo(HaveOccurred()) }) It("returns an empty result", func() { pairs, err := session.ListAcquiredValues(unowned) Expect(err).NotTo(HaveOccurred()) Expect(pairs).To(Equal(map[string][]byte{})) }) }) })