func (s *S) TestNewWithExclusiveSearch(c *C) { l := local.New(path) l.AddClient(local.Client{Name: "Test Client"}) output := newWithArgs([]string{"bad"}, l) c.Assert(output, Equals, "No clients matched your search.\n") }
func NewContext( localStoragePath string, args []string, logger *log.Logger, fatal *log.Logger, ) (c G5CLIExecutionContext) { l := local.New(localStoragePath) if !l.IsPersisted() { logger.Println("No locally cached data. Enhance...") if err := g5hub.PopulateLocalStorage(l); err != nil { fatal.Printf(err.Error() + "\n") os.Exit(1) } l.Persist() } if l.ShouldNag() { l.LastNagged = time.Now() l.Persist() layout := "Mon, 01/02/06" s := l.LastUpdated.Format(layout) logger.Printf("Your last update was %v. You should consider running the update command. I'll nag you again soon.\n", s) } return G5CLIExecutionContext{ LocalStorage: l, Args: args, Logger: logger, Fatal: fatal, Heroku: CLIHerokuExecutor{SuccessLogger: logger, ErrorLogger: fatal}, } }
func (s *S) TestNewWithNoArgs(c *C) { l := local.New(path) l.AddClient(local.Client{Name: "Test Client"}) output := newWithArgs([]string{}, l) c.Assert(output, Equals, "You must pass a client name.\n") }
func (s *S) TestNewWithUppercaseSearch(c *C) { l := local.New(path) l.AddClient(local.Client{Name: "Test Client"}) output := newWithArgs([]string{"TEST"}, l) c.Assert(output, Equals, "Test Client\n") }
func (s *S) TestNewWithoutArgs(c *C) { l := local.New(path) l.AddClient(local.Client{Name: "Test Client"}) output := newWithArgs([]string{}, l) c.Assert(output, Equals, "Test Client\n") }
func (s *S) TestNewWithInclusiveSearch(c *C) { l := local.New(path) l.AddClient(local.Client{Name: "Test Client"}) l.AddClient(local.Client{Name: "Other Client"}) output := newWithArgs([]string{"test"}, l) c.Assert(output, Equals, "Test Client\n") }
func (s *S) TestNewWithAmbiguousClient(c *C) { l := local.New(path) l.AddClient(local.Client{Name: "Test Client"}) l.AddClient(local.Client{Name: "Test Client 2"}) output := newWithArgs([]string{"test"}, l) c.Assert(output, Equals, "Your search terms were ambiguous and matched multiple clients.\n") }
func (s *S) TestNewWithFoundClientAndLocations(c *C) { l := local.New(path) client := local.Client{Name: "Test Client", UID: "https://example.com/location_uid"} client.Locations = append(client.Locations, local.Location{Name: "Test Location"}) l.AddClient(client) output := newWithArgs([]string{"test"}, l) didMatch, _ := regexp.MatchString("Test Location", output) c.Assert(didMatch, Equals, true) }
func (s *S) TestNewWithFoundClientNoLocations(c *C) { l := local.New(path) l.AddClient(local.Client{Name: "Test Client", UID: "https://example.com/uid"}) output := newWithArgs([]string{"test"}, l) didMatch, _ := regexp.MatchString("Test Client", output) c.Assert(didMatch, Equals, true) didMatch, _ = regexp.MatchString("https://example.com/uid", output) c.Assert(didMatch, Equals, true) didMatch, _ = regexp.MatchString("None", output) c.Assert(didMatch, Equals, true) }
func (s *G5HubSuite) TestPopulateFromMarkupGood() { l := local.New(path) n := parsedClients(s, "clients.html") err := populateFromMarkup(l, n) s.NoError(err) s.Len(l.Clients, 1) client := l.Clients[0] s.Equal("G5 Multifamily", client.Name) s.Equal("https://g5-hub.herokuapp.com/clients/g5-c-1soj8m6e-g5-multifamily", client.UID) s.Equal("g5-c-1soj8m6e-g5-multifamily", client.URN) s.Len(client.Locations, 1) location := client.Locations[0] s.Equal("1212 Apartments", location.Name) s.Equal( "https://g5-hub.herokuapp.com/clients/g5-c-1soj8m6e-g5-multifamily/locations/g5-cl-1spcif5s-1212-apartments", location.UID, ) s.Equal("g5-cl-1spcif5s-1212-apartments", location.URN) }
func (s *HerokuSuite) SetupTest() { s.h = TestHerokuExecutor{} s.l = local.New(path) }