示例#1
0
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")
}
示例#2
0
文件: context.go 项目: G5/g5cli
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},
	}
}
示例#3
0
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")
}
示例#4
0
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")
}
示例#5
0
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")
}
示例#6
0
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")
}
示例#7
0
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")
}
示例#8
0
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)
}
示例#9
0
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)
}
示例#10
0
文件: g5hub_test.go 项目: G5/g5cli
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)
}
示例#11
0
文件: heroku_test.go 项目: G5/g5cli
func (s *HerokuSuite) SetupTest() {
	s.h = TestHerokuExecutor{}
	s.l = local.New(path)
}