func (matcher *SliceMatcher) Match(actual interface{}) (success bool, err error) { actualStrings, ok := actual.([]string) if !ok { return false, nil } allStringsMatched := make([]bool, len(matcher.expected)) for index, expectedArray := range matcher.expected { for _, actualValue := range actualStrings { allStringsFound := true for _, expectedValue := range expectedArray { allStringsFound = allStringsFound && strings.Contains(terminal.Decolorize(actualValue), expectedValue) } if allStringsFound { allStringsMatched[index] = true break } } } for index, value := range allStringsMatched { if !value { matcher.failedAtIndex = index return false, nil } } return true, nil }
func matchSingleLine(actual string, expected []string) (bool, string) { matched := false for i, target := range expected { if index := strings.Index(terminal.Decolorize(actual), target); index != -1 { if i == len(expected)-1 { return true, "" } matched = true actual = actual[index+len(target):] } else if matched { return false, target } else { return false, "" } } return false, "" }
cb(route2) cb(route3) return nil } }) It("lists routes", func() { runCommand() Expect(ui.Outputs()).To(BeInDisplayOrder( []string{"Getting routes for org my-org / space my-space as my-user ..."}, []string{"space", "host", "domain", "port", "path", "type", "apps", "service"}, )) Expect(terminal.Decolorize(ui.Outputs()[3])).To(MatchRegexp(`^my-space\s+hostname-1\s+example.com\s+dora\s+test-service\s*$`)) Expect(terminal.Decolorize(ui.Outputs()[4])).To(MatchRegexp(`^my-space\s+hostname-2\s+cookieclicker\.co\s+/foo\s+dora,bora\s*$`)) Expect(terminal.Decolorize(ui.Outputs()[5])).To(MatchRegexp(`^my-space\s+cookieclicker\.co\s+9090\s+tcp\s+dora,bora\s*$`)) }) }) Context("when there are routes in different spaces", func() { BeforeEach(func() { routeRepo.ListAllRoutesStub = func(cb func(models.Route) bool) error { space1 := models.SpaceFields{Name: "space-1"} space2 := models.SpaceFields{Name: "space-2"} domain := models.DomainFields{Name: "example.com"} domain2 := models.DomainFields{Name: "cookieclicker.co"}
. "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("loggregatorMessage", func() { Describe("ToLog", func() { var date time.Time BeforeEach(func() { date = time.Date(2014, 4, 4, 11, 39, 20, 5, time.UTC) }) Context("when the message comes", func() { It("include the instance index", func() { msg := testlogs.NewLogMessage("Hello World!", "", "DEA", "4", logmessage.LogMessage_OUT, date) Expect(terminal.Decolorize(msg.ToLog(time.UTC))).To(Equal("2014-04-04T11:39:20.00+0000 [DEA/4] OUT Hello World!")) }) It("doesn't include the instance index if sourceID is empty", func() { msg := testlogs.NewLogMessage("Hello World!", "", "DEA", "", logmessage.LogMessage_OUT, date) Expect(terminal.Decolorize(msg.ToLog(time.UTC))).To(Equal("2014-04-04T11:39:20.00+0000 [DEA] OUT Hello World!")) }) }) Context("when the message was written to stderr", func() { It("shows the log type as 'ERR'", func() { msg := testlogs.NewLogMessage("Hello World!", "", "DEA", "4", logmessage.LogMessage_ERR, date) Expect(terminal.Decolorize(msg.ToLog(time.UTC))).To(Equal("2014-04-04T11:39:20.00+0000 [DEA/4] ERR Hello World!")) }) })
} return []models.V3Route{ { Host: "route-2-host", Path: "", }, }, nil } }) It("prints a table of the results", func() { Expect(runCLIErr).NotTo(HaveOccurred()) outputs := make([]string, len(ui.Outputs())) for i := range ui.Outputs() { outputs[i] = terminal.Decolorize(ui.Outputs()[i]) } Expect(outputs).To(ConsistOf( MatchRegexp(`name.*requested state.*instances.*memory.*disk.*urls`), MatchRegexp("app-1-name.*stopped.*1.*1G.*2G.*route-1-host/route-1-path, route-1-host-2"), MatchRegexp("app-2-name.*running.*2.*512M.*1G.*route-2-host"), )) }) }) Context("when getting the routes fails", func() { BeforeEach(func() { repository.GetRoutesReturns([]models.V3Route{}, errors.New("get-routes-err")) }) It("fails with error", func() {
{ Name: "quota-unlimited-routes", MemoryLimit: 434, InstanceMemoryLimit: 1, RoutesLimit: -1, ServicesLimit: 2, NonBasicServicesAllowed: false, AppInstanceLimit: 10, ReservedRoutePorts: "4", }, }, nil) }) It("lists quotas", func() { Expect(Expect(runCommand()).To(HavePassedRequirements())).To(HavePassedRequirements()) Expect(terminal.Decolorize(ui.Outputs()[0])).To(Equal("Getting quotas as my-user...")) Expect(terminal.Decolorize(ui.Outputs()[1])).To(Equal("OK")) Expect(terminal.Decolorize(ui.Outputs()[3])).To(MatchRegexp("name\\s*total memory\\s*instance memory\\s*routes\\s*service instances\\s*paid plans\\s*app instances\\s*route ports\\s*")) Expect(terminal.Decolorize(ui.Outputs()[4])).To(MatchRegexp("quota-name\\s*1G\\s*512M\\s*111\\s*222\\s*allowed\\s*unlimited\\s*4")) Expect(terminal.Decolorize(ui.Outputs()[5])).To(MatchRegexp("quota-non-basic-not-allowed\\s*434M\\s*unlimited\\s*1\\s*2\\s*disallowed\\s*10\\s*4")) Expect(terminal.Decolorize(ui.Outputs()[6])).To(MatchRegexp("quota-unlimited-routes\\s*434M\\s*1M\\s*unlimited\\s*2\\s*disallowed\\s*10\\s*4")) }) It("displays unlimited services properly", func() { quotaRepo.FindAllReturns([]models.QuotaFields{ { Name: "quota-with-no-limit-to-services", MemoryLimit: 434, InstanceMemoryLimit: 1, RoutesLimit: 2, ServicesLimit: -1,