コード例 #1
0
ファイル: contain_substrings.go プロジェクト: matanzit/cli
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
}
コード例 #2
0
ファイル: be_in_display_order.go プロジェクト: Reejoshi/cli
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, ""
}
コード例 #3
0
ファイル: contains_substrings.go プロジェクト: GABONIA/cli
func (matcher *SliceMatcher) Match(actual interface{}) (success bool, err error) {
	actualStrings, ok := actual.([]string)
	if !ok {
		return false, nil
	}

	matcher.failedAtIndex = 0
	for _, actualValue := range actualStrings {
		allStringsFound := true
		for _, expectedValue := range matcher.expected[matcher.failedAtIndex] {
			allStringsFound = allStringsFound && strings.Contains(terminal.Decolorize(actualValue), expectedValue)
		}

		if allStringsFound {
			matcher.failedAtIndex++
			if matcher.failedAtIndex == len(matcher.expected) {
				return true, nil
			}
		}
	}

	return false, nil
}
コード例 #4
0
ファイル: routes_test.go プロジェクト: jasonkeene/cli
				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"}
コード例 #5
0
ファイル: logs_test.go プロジェクト: vframbach/cli
					[]string{"Connected, tailing logs for app", "my-org", "my-space", "my-user"},
				))
			})
		})

		Describe("Helpers", 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!", app.Guid, "DEA", "4", logmessage.LogMessage_OUT, date)
					Expect(terminal.Decolorize(LogMessageOutput(msg, 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!", app.Guid, "DEA", "", logmessage.LogMessage_OUT, date)
					Expect(terminal.Decolorize(LogMessageOutput(msg, 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!", app.Guid, "DEA", "4", logmessage.LogMessage_ERR, date)
					Expect(terminal.Decolorize(LogMessageOutput(msg, time.UTC))).To(Equal("2014-04-04T11:39:20.00+0000 [DEA/4]      ERR Hello World!"))
				})
			})
コード例 #6
0
ファイル: v3apps_test.go プロジェクト: jasonkeene/cli
							}

							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() {
コード例 #7
0
ファイル: quotas_test.go プロジェクト: Reejoshi/cli
				{
					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,