func getAllocatedInfo(repo *redis.RemoteRepository) (Allocated, error) { allocated := Allocated{} allocatedInstances, err := repo.AllInstances() if err != nil { return allocated, err } for _, instance := range allocatedInstances { bindingIDs, err := repo.BindingsForInstance(instance.ID) if err != nil { return allocated, err } c := Cluster{ ID: instance.ID, Hosts: []string{instance.Host}, } for _, id := range bindingIDs { c.Bindings = append(c.Bindings, Binding{ID: id}) } allocated.Clusters = append(allocated.Clusters, c) } allocated.Count = len(allocatedInstances) return allocated, nil }
AllocatedInstances: []*redis.Instance{ &redis.Instance{ Host: "10.0.0.3", ID: "dedicated-instance", }, }, } putStatefileContents(statefilePath, statefile) }) Context("When the state file can be read", func() { It("loads its state from the state file", func() { repo, err := redis.NewRemoteRepository(fakeAgentClient, config, logger) Expect(err).ToNot(HaveOccurred()) allocatedInstances, err := repo.AllInstances() Expect(err).ToNot(HaveOccurred()) Expect(repo.InstanceLimit()).To(Equal(3)) Expect(len(allocatedInstances)).To(Equal(1)) Expect(*allocatedInstances[0]).To(Equal(*statefile.AllocatedInstances[0])) }) It("adds new nodes from config", func() { nodes := append(config.RedisConfiguration.Dedicated.Nodes, "10.0.0.4") config.RedisConfiguration.Dedicated.Nodes = nodes repo, err := redis.NewRemoteRepository(fakeAgentClient, config, logger) Expect(err).ToNot(HaveOccurred()) availableInstances := repo.AvailableInstances() Expect(len(availableInstances)).To(Equal(3))