예제 #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
파일: clientshow_test.go 프로젝트: G5/g5cli
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
파일: clientshow_test.go 프로젝트: G5/g5cli
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
파일: clientshow_test.go 프로젝트: G5/g5cli
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
파일: clientshow_test.go 프로젝트: G5/g5cli
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)
}