コード例 #1
0
ファイル: routing_api_test.go プロジェクト: Reejoshi/cli
			BeforeEach(func() {
				routingAPIServer = ghttp.NewServer()
				routingAPIServer.RouteToHandler("GET", "/v1/router_groups",
					func(w http.ResponseWriter, req *http.Request) {
						responseBody := []byte(`[
			{
				  "guid": "bad25cff-9332-48a6-8603-b619858e7992",
					"name": "default-tcp",
					"type": "tcp"
			}]`)
						w.Header().Set("Content-Length", strconv.Itoa(len(responseBody)))
						w.Header().Set("Content-Type", "application/json")
						w.WriteHeader(http.StatusOK)
						w.Write(responseBody)
					})
				configRepo.SetRoutingAPIEndpoint(routingAPIServer.URL())
			})

			It("lists routing groups", func() {
				cb := func(grp models.RouterGroup) bool {
					Expect(grp).To(Equal(models.RouterGroup{
						GUID: "bad25cff-9332-48a6-8603-b619858e7992",
						Name: "default-tcp",
						Type: "tcp",
					}))
					return true
				}
				err := repo.ListRouterGroups(cb)
				Expect(err).ToNot(HaveOccurred())
			})
		})
コード例 #2
0
ファイル: routing_api_test.go プロジェクト: Reejoshi/cli
)

var _ = Describe("RoutingApi", func() {
	var (
		config      coreconfig.Repository
		requirement requirements.RoutingAPIRequirement
	)

	BeforeEach(func() {
		config = testconfig.NewRepositoryWithAccessToken(coreconfig.TokenInfo{Username: "******"})
		requirement = requirements.NewRoutingAPIRequirement(config)
	})

	Context("when the config has a zero-length RoutingAPIEndpoint", func() {
		BeforeEach(func() {
			config.SetRoutingAPIEndpoint("")
		})

		It("errors", func() {
			err := requirement.Execute()
			Expect(err.Error()).To(ContainSubstring("This command requires the Routing API. Your targeted endpoint reports it is not enabled."))
		})
	})

	Context("when the config has a RoutingAPIEndpoint", func() {
		BeforeEach(func() {
			config.SetRoutingAPIEndpoint("api.example.com")
		})

		It("does not error", func() {
			err := requirement.Execute()