func seedRouterGroups(cfg config.Config, logger lager.Logger, database db.DB) { // seed router groups from config if len(cfg.RouterGroups) > 0 { routerGroups, _ := database.ReadRouterGroups() // if config not empty and db is empty, seed if len(routerGroups) == 0 { for _, rg := range cfg.RouterGroups { guid, err := uuid.NewV4() if err != nil { logger.Error("failed to generate a guid for router group", err) os.Exit(1) } rg.Guid = guid.String() logger.Info("seeding", lager.Data{"router-group": rg}) err = database.SaveRouterGroup(rg) if err != nil { logger.Error("failed to save router group from config", err) os.Exit(1) } } } } }
Expect(fakeKeysAPI.DeleteCallCount()).To(Equal(1)) }) }) }) }) Context("RouterGroup", func() { Context("Save", func() { Context("when router group is missing a guid", func() { It("does not save the router group", func() { routerGroup := models.RouterGroup{ Name: "router-group-1", Type: "tcp", ReservablePorts: "10-20,25", } err = etcd.SaveRouterGroup(routerGroup) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("missing guid")) }) }) Context("when router group does not exist", func() { It("saves the router group", func() { g, err := uuid.NewV4() Expect(err).NotTo(HaveOccurred()) guid := g.String() routerGroup := models.RouterGroup{ Name: "router-group-1", Type: "tcp", Guid: guid,