예제 #1
0
func deliverStoryHandler(token string, projectId string, storyId int) http.HandlerFunc {
	body := `{"current_state":"delivered"}`
	return ghttp.CombineHandlers(
		ghttp.VerifyRequest(
			"PUT",
			fmt.Sprintf("/services/v5/projects/%s/stories/%d", projectId, storyId),
		), ghttp.VerifyHeaderKV("X-TrackerToken", token),
		ghttp.VerifyJSON(body),
	)
}
예제 #2
0
func deliverStoryCommentHandler(token string, projectId string, storyId int, comment string) http.HandlerFunc {
	body := fmt.Sprintf(`{"text":"%s"}`, comment)
	return ghttp.CombineHandlers(
		ghttp.VerifyRequest(
			"POST",
			fmt.Sprintf("/services/v5/projects/%s/stories/%d/comments", projectId, storyId),
		), ghttp.VerifyHeaderKV("X-TrackerToken", token),
		ghttp.VerifyJSON(body),
	)
}
예제 #3
0
		gateway := net.NewCloudControllerGateway(configRepo, time.Now, &testterm.FakeUI{})
		repo = NewCloudControllerServiceKeyRepository(configRepo, gateway)
	})

	AfterEach(func() {
		ccServer.Close()
	})

	Describe("CreateServiceKey", func() {
		It("tries to create the service key", func() {
			ccServer.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("POST", "/v2/service_keys"),
					ghttp.RespondWith(http.StatusCreated, nil),
					ghttp.VerifyJSON(`{"service_instance_guid": "fake-instance-guid", "name": "fake-key-name"}`),
				),
			)

			err := repo.CreateServiceKey("fake-instance-guid", "fake-key-name", nil)
			Expect(err).NotTo(HaveOccurred())
			Expect(ccServer.ReceivedRequests()).To(HaveLen(1))
		})

		Context("when the service key exists", func() {
			BeforeEach(func() {
				ccServer.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("POST", "/v2/service_keys"),
						ghttp.RespondWith(http.StatusBadRequest, `{"code":360001,"description":"The service key name is taken: exist-service-key"}`),
					),
예제 #4
0
				completed,
				assigneeID,
				recurrenceType,
				recurrenceCount,
				"1968-01-02",
				starred,
			)

			server.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("POST", "/tasks"),
					ghttp.VerifyHeader(http.Header{
						"X-Access-Token": []string{dummyAccessToken},
						"X-Client-ID":    []string{dummyClientID},
					}),
					ghttp.VerifyJSON(expectedBody),
				),
			)

			client.CreateTask(
				title,
				listID,
				assigneeID,
				completed,
				recurrenceType,
				recurrenceCount,
				dueDate,
				starred,
			)

			Expect(server.ReceivedRequests()).Should(HaveLen(1))
예제 #5
0
			})

			It("returns an error", func() {
				_, err := client.FindByUsername("*****@*****.**")
				Expect(err).To(HaveOccurred())
			})
		})
	})

	Describe("Create", func() {
		Context("when the user does not exist", func() {
			BeforeEach(func() {
				ccServer.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("POST", "/v2/users"),
						ghttp.VerifyJSON(`{"guid":"my-user-guid"}`),
					),
				)
				uaaServer.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("POST", "/Users"),
						ghttp.VerifyHeader(http.Header{
							"accept": []string{"application/json"},
						}),
						ghttp.VerifyJSON(`{
							"userName":"******",
							"emails":[{"value":"my-user"}],
							"password":"******",
							"name":{
								"givenName":"my-user",
								"familyName":"my-user"}
						PersistentDisk: rackhdapi.PersistentDiskSettings{
							DiskCID:    "valid_disk_cid_2",
							Location:   "/dev/sdb",
							IsAttached: false,
						},
					}
					bodyBytes, err := json.Marshal(body)

					server.AppendHandlers(
						ghttp.CombineHandlers(
							ghttp.VerifyRequest("GET", "/api/common/nodes"),
							ghttp.RespondWith(http.StatusOK, expectedNodesData),
						),
						ghttp.CombineHandlers(
							ghttp.VerifyRequest("PATCH", "/api/common/nodes/55e79eb14e66816f6152fffb"),
							ghttp.VerifyJSON(string(bodyBytes)),
						),
					)

					err = DetachDisk(cpiConfig, extInput)
					Expect(len(server.ReceivedRequests())).To(Equal(2))
					Expect(err).NotTo(HaveOccurred())
				})
			})
		})
	})

	Context("given a nonexistent disk CID", func() {
		It("returns an error", func() {
			jsonInput := []byte(`[
					"valid_vm_cid_1",
			productFileID = 3456

			expectedRequestBody = `{"product_file":{"id":3456}}`
		)

		Context("when the server responds with a 204 status code", func() {
			It("returns without error", func() {
				server.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("PATCH", fmt.Sprintf(
							"%s/products/%d/releases/%d/add_product_file",
							apiPrefix,
							productID,
							releaseID,
						)),
						ghttp.VerifyJSON(expectedRequestBody),
						ghttp.RespondWith(http.StatusNoContent, nil),
					),
				)

				err := client.AddProductFile(productID, releaseID, productFileID)
				Expect(err).NotTo(HaveOccurred())
			})
		})

		Context("when the server responds with a non-201 status code", func() {
			It("returns an error", func() {
				server.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("PATCH", fmt.Sprintf(
							"%s/products/%d/releases/%d/add_product_file",
예제 #8
0
	Describe("UpdateRelease", func() {
		It("submits the updated values for a release", func() {
			release := pivnet.Release{
				ID: 42,
				Eula: &pivnet.Eula{
					Slug: "some-eula",
					ID:   15,
				},
			}

			patchURL := fmt.Sprintf("%s/products/%s/releases/%d", apiPrefix, "banana-slug", release.ID)

			server.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("PATCH", patchURL),
					ghttp.VerifyJSON(`{"release":{"id": 42, "eula":{"slug":"some-eula","id":15}}}`),
					ghttp.RespondWith(http.StatusOK, nil),
				),
			)

			Expect(client.UpdateRelease("banana-slug", release)).To(Succeed())
		})

		Context("when the server responds with a non-200 status code", func() {
			It("returns the error", func() {
				release := pivnet.Release{ID: 111}
				patchURL := fmt.Sprintf("%s/products/%s/releases/%d", apiPrefix, "banana-slug", release.ID)

				server.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("PATCH", patchURL),
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("PUT", fmt.Sprintf("/v2/user_provided_service_instances/%s/routes/%s", serviceInstanceGuid, routeGuid)),
					ghttp.RespondWith(http.StatusCreated, nil),
				),
			)
			err := routeServiceBindingRepo.Bind(serviceInstanceGuid, routeGuid, true, "")
			Expect(err).NotTo(HaveOccurred())
			Expect(ccServer.ReceivedRequests()).To(HaveLen(1))
		})

		It("creates the service binding with the provided body", func() {
			ccServer.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("PUT", fmt.Sprintf("/v2/user_provided_service_instances/%s/routes/%s", serviceInstanceGuid, routeGuid)),
					ghttp.RespondWith(http.StatusCreated, nil),
					ghttp.VerifyJSON(`{"some":"json"}`),
				),
			)
			err := routeServiceBindingRepo.Bind(serviceInstanceGuid, routeGuid, true, `{"some":"json"}`)
			Expect(err).NotTo(HaveOccurred())
			Expect(ccServer.ReceivedRequests()).To(HaveLen(1))
		})

		Context("when an API error occurs", func() {
			BeforeEach(func() {
				ccServer.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("PUT", fmt.Sprintf("/v2/service_instances/%s/routes/%s", serviceInstanceGuid, routeGuid)),
						ghttp.RespondWith(http.StatusBadRequest, `{"code":61003,"description":"Route does not exist"}`),
					),
				)
예제 #10
0
		})

		AfterEach(func() {
			if ccServer != nil {
				ccServer.Close()
			}
		})

		Context("when no host, path, or port are given", func() {
			BeforeEach(func() {
				ccServer.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("POST", "/v2/routes", "inline-relations-depth=1&async=true"),
						ghttp.VerifyJSON(`
							{
								"domain_guid":"my-domain-guid",
								"space_guid":"my-space-guid"
							}
						`),
						ghttp.VerifyHeader(http.Header{
							"accept": []string{"application/json"},
						}),
					),
				)
			})

			It("tries to create a route", func() {
				repo.CreateInSpace("", "", "my-domain-guid", "my-space-guid", 0, false)
				Expect(ccServer.ReceivedRequests()).To(HaveLen(1))
			})

			Context("when creating the route succeeds", func() {
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("PUT", fmt.Sprintf("/v2/user_provided_service_instances/%s/routes/%s", serviceInstanceGUID, routeGUID)),
					ghttp.RespondWith(http.StatusCreated, nil),
				),
			)
			err := routeServiceBindingRepo.Bind(serviceInstanceGUID, routeGUID, true, "")
			Expect(err).NotTo(HaveOccurred())
			Expect(ccServer.ReceivedRequests()).To(HaveLen(1))
		})

		It("creates the service binding with the provided body wrapped in parameters", func() {
			ccServer.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("PUT", fmt.Sprintf("/v2/user_provided_service_instances/%s/routes/%s", serviceInstanceGUID, routeGUID)),
					ghttp.RespondWith(http.StatusCreated, nil),
					ghttp.VerifyJSON(`{"parameters":{"some":"json"}}`),
				),
			)
			err := routeServiceBindingRepo.Bind(serviceInstanceGUID, routeGUID, true, `{"some":"json"}`)
			Expect(err).NotTo(HaveOccurred())
			Expect(ccServer.ReceivedRequests()).To(HaveLen(1))
		})

		Context("when an API error occurs", func() {
			BeforeEach(func() {
				ccServer.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("PUT", fmt.Sprintf("/v2/service_instances/%s/routes/%s", serviceInstanceGUID, routeGUID)),
						ghttp.RespondWith(http.StatusBadRequest, `{"code":61003,"description":"Route does not exist"}`),
					),
				)
예제 #12
0
		// Perform the test by running main() with the command line args set
		It(strings.Join(testCase.CmdArgs, " "), func() {
			//server := httptest.NewTLSServer(http.HandlerFunc(handler))
			server := ghttp.NewServer()
			defer server.Close()

			// construct list of verifiers
			url := regexp.MustCompile(`https?://[^/]+(/[^?]+)\??(.*)`).
				FindStringSubmatch(testCase.RR.URI)
			//fmt.Fprintf(os.Stderr, "URL: %#v\n", url)
			handlers := []http.HandlerFunc{
				ghttp.VerifyRequest(testCase.RR.Verb, url[1], url[2]),
			}
			if len(testCase.RR.ReqBody) > 0 {
				handlers = append(handlers,
					ghttp.VerifyJSON(testCase.RR.ReqBody))
			}
			for k := range testCase.RR.ReqHeader {
				handlers = append(handlers,
					ghttp.VerifyHeaderKV(k, testCase.RR.ReqHeader.Get(k)))
			}
			respHeader := make(http.Header)
			for k, v := range testCase.RR.RespHeader {
				respHeader[k] = v
			}
			handlers = append(handlers,
				ghttp.RespondWith(testCase.RR.Status, testCase.RR.RespBody,
					respHeader))
			server.AppendHandlers(ghttp.CombineHandlers(handlers...))

			os.Args = append([]string{
예제 #13
0
		)

		BeforeEach(func() {
			productSlug = "banana-slug"
			releaseID = 42
			EULAAcceptanceURL = fmt.Sprintf(apiPrefix+"/products/%s/releases/%d/eula_acceptance", productSlug, releaseID)
		})

		It("accepts the EULA for a given release and product ID", func() {
			response := fmt.Sprintf(`{"accepted_at": "2016-01-11","_links":{}}`)

			server.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("POST", EULAAcceptanceURL),
					ghttp.VerifyHeaderKV("Authorization", fmt.Sprintf("Token %s", token)),
					ghttp.VerifyJSON(`{}`),
					ghttp.RespondWith(http.StatusOK, response),
				),
			)

			Expect(client.AcceptEULA(productSlug, releaseID)).To(Succeed())
		})

		Context("when any other non-200 status code comes back", func() {
			It("returns an error", func() {
				server.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("POST", EULAAcceptanceURL),
						ghttp.VerifyHeaderKV("Authorization", fmt.Sprintf("Token %s", token)),
						ghttp.VerifyJSON(`{}`),
						ghttp.RespondWith(http.StatusTeapot, nil),
예제 #14
0
				OccurredBefore: 1433091819000,
				OccurredAfter:  1000000000000,
				SinceVersion:   1,
			}
			activities, err := client.InProject(99).StoryActivity(560, query)
			Ω(activities).Should(HaveLen(4))
			Ω(err).ToNot(HaveOccurred())
		})
	})

	Describe("delivering a story", func() {
		It("HTTP PUTs it in its place", func() {
			server.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("PUT", "/services/v5/projects/99/stories/15225523"),
					ghttp.VerifyJSON(`{"current_state":"delivered"}`),
					verifyTrackerToken(),

					ghttp.RespondWith(http.StatusOK, ""),
				),
			)

			client := tracker.NewClient("api-token")

			err := client.InProject(99).DeliverStory(15225523)
			Ω(err).ShouldNot(HaveOccurred())
		})

		It("HTTP PUTs it in its place with a comment", func() {
			comment := "some delivery comment"
			server.AppendHandlers(
예제 #15
0
		var apiKey string = "S0m3Ap1K3y"
		var accountId string = "123abc"
		auth := &main.Auth{
			Email:    email,
			Password: password,
		}

		BeforeEach(func() {
			server = ghttp.NewServer()
			main.BaseUrl = server.URL()

			server.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("POST", "/auth"),
					ghttp.VerifyHeader(http.Header{"User-Agent": []string{"imgix-cli v0.1.0"}}),
					ghttp.VerifyJSON(fmt.Sprintf(`{ "password": "******", "email": "%s" }`, password, email)),
					ghttp.RespondWith(http.StatusOK, fmt.Sprintf(`{
						"account_id": "%s",
						"api_key": "%s",
						"email": "%s"
					}`, accountId, apiKey, email)),
				),
			)
		})

		AfterEach(func() {
			server.Close()
		})

		It("sends off the request", func() {
			main.PostAuth(auth)
예제 #16
0
	Describe("creating a new list", func() {
		var title string

		BeforeEach(func() {
			title = "a list"
		})

		It("performs POST requests with correct headers to /lists", func() {
			server.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("POST", "/lists"),
					ghttp.VerifyHeader(http.Header{
						"X-Access-Token": []string{dummyAccessToken},
						"X-Client-ID":    []string{dummyClientID},
					}),
					ghttp.VerifyJSON(`{"title":"a list"}`),
				),
			)

			client.CreateList(title)

			Expect(server.ReceivedRequests()).Should(HaveLen(1))
		})

		Context("when the request is valid", func() {
			It("returns successfully", func() {
				expectedList := wl.List{ID: 2345}

				// Marshal and unmarshal to ensure exact object is returned
				// - this avoids odd behavior with the time fields
				expectedBody, err := json.Marshal(expectedList)
예제 #17
0
	"github.com/concourse/go-concourse/concourse"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"github.com/onsi/gomega/ghttp"
)

var _ = Describe("CheckResource", func() {
	Context("when ATC request succeeds", func() {
		BeforeEach(func() {
			expectedURL := "/api/v1/teams/some-team/pipelines/mypipeline/resources/myresource/check"
			atcServer.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("POST", expectedURL),
					ghttp.VerifyJSON(`{"from":{"ref":"fake-ref"}}`),
					ghttp.RespondWithJSONEncoded(http.StatusOK, ""),
				),
			)
		})

		It("sends check resource request to ATC", func() {
			found, err := team.CheckResource("mypipeline", "myresource", atc.Version{"ref": "fake-ref"})
			Expect(err).NotTo(HaveOccurred())
			Expect(found).To(BeTrue())

			Expect(atcServer.ReceivedRequests()).To(HaveLen(1))
		})
	})

	Context("when pipeline or resource does not exist", func() {
				),
			)
		})

		Context("when there is a VM left on the node", func() {
			It("deletes the disk", func() {
				jsonInput := []byte(`[
						"valid_disk_cid_3"
					]`)
				err := json.Unmarshal(jsonInput, &extInput)
				Expect(err).NotTo(HaveOccurred())

				server.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("PATCH", "/api/common/nodes/55e79e9f4e66816f6152fff5"),
						ghttp.VerifyJSON(string(expectedDeleteDiskBodyBytes)),
					),
				)

				err = DeleteDisk(cpiConfig, extInput)
				Expect(len(server.ReceivedRequests())).To(Equal(2))
				Expect(err).NotTo(HaveOccurred())
			})
		})

		Context("when there is no VM left on the node", func() {
			It("deletes the disk and sets the status to available", func() {
				jsonInput := []byte(`[
						"valid_disk_cid_1"
					]`)
				err := json.Unmarshal(jsonInput, &extInput)
예제 #19
0
				SpaceGUID:     &spaceGUID,
				StackGUID:     &stackGUID,
				Command:       &command,
				Memory:        &memory,
				DiskQuota:     &diskQuota,
				InstanceCount: &instanceCount,
			}

			ccServer.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("POST", "/v2/apps"),
					ghttp.VerifyJSON(`{
						"name":"my-cool-app",
						"instances":3,
						"buildpack":"buildpack-url",
						"memory":2048,
						"disk_quota": 512,
						"space_guid":"some-space-guid",
						"stack_guid":"some-stack-guid",
						"command":"some-command"
					}`),
				),
			)
		})

		AfterEach(func() {
			ccServer.Close()
		})

		It("tries to create the app", func() {
			repo.Create(appParams)
			Expect(ccServer.ReceivedRequests()).To(HaveLen(1))
예제 #20
0
			server = ghttp.NewServer()
			main.BaseUrl = server.URL()
			editableSource = &main.EditableSource{
				Name: sourceName,
			}

			firstResponse := `{}`
			secondResponse := `{}`

			server.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("POST", "/sources/"+sourceId, ""),
					ghttp.RespondWithJSONEncoded(http.StatusOK, firstResponse),
					correctUserAgent,
					correctAuthHeader,
					ghttp.VerifyJSON(fmt.Sprintf(`{ "name": "%s" }`, sourceName)),
				),
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("POST", "/sources/"+sourceId+"/config", ""),
					ghttp.RespondWithJSONEncoded(http.StatusOK, secondResponse),
					correctUserAgent,
					correctAuthHeader,
					ghttp.VerifyJSON(fmt.Sprintf(`{
						"cache_ttl_browser": 0,
	          "cache_ttl_error": 0,
	          "cache_ttl_fetch": 0,
	          "cache_ttl_render": 0,
	          "crossdomain_cors_enabled": false,
	          "crossdomain_cors_hosts": "",
	          "crossdomain_xml_enabled": false,
	          "crossdomain_xml_hosts": "",
예제 #21
0
				OccurredBefore: 1433091819000,
				OccurredAfter:  1000000000000,
				SinceVersion:   1,
			}
			activities, err := client.InProject(99).StoryActivity(560, query)
			Ω(activities).Should(HaveLen(4))
			Ω(err).ToNot(HaveOccurred())
		})
	})

	Describe("delivering a story", func() {
		It("HTTP PUTs it in its place", func() {
			server.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("PUT", "/services/v5/projects/99/stories/15225523"),
					ghttp.VerifyJSON(`{"current_state":"delivered"}`),
					verifyTrackerToken(),

					ghttp.RespondWith(http.StatusOK, `{
						"id": 1234,
						"project_id": 5678,
						"name": "Exhaust ports are ray shielded",
						"url": "https://some-url.biz/1234"
					}`),
				),
			)

			client := tracker.NewClient("api-token")

			story, err := client.InProject(99).DeliverStory(15225523)
			Ω(err).ShouldNot(HaveOccurred())
예제 #22
0
	"github.com/onsi/gomega/gbytes"
	"github.com/onsi/gomega/gexec"
	"github.com/onsi/gomega/ghttp"
)

var _ = Describe("RenamePipeline", func() {
	var newName string
	BeforeEach(func() {
		expectedURL := "/api/v1/pipelines/some-pipeline/rename"
		newName = "brandnew"

		atcServer.AppendHandlers(
			ghttp.CombineHandlers(
				ghttp.VerifyRequest("PUT", expectedURL),
				ghttp.VerifyJSON(fmt.Sprintf(`{"name":%q}`, newName)),
				ghttp.RespondWith(http.StatusNoContent, ""),
			),
		)
	})

	Context("when not specifying a pipeline name", func() {
		It("fails and says you should provide a pipeline name", func() {
			flyCmd := exec.Command(flyPath, "-t", targetName, "rename-pipeline", "-n", "some-new-name")

			sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
			Expect(err).NotTo(HaveOccurred())

			Eventually(sess).Should(gexec.Exit(1))

			Expect(sess.Err).To(gbytes.Say("error: the required flag `" + osFlag("o", "old-name") + "' was not specified"))
예제 #23
0
				OccurredBefore: 1433091819000,
				OccurredAfter:  1000000000000,
				SinceVersion:   1,
			}
			activities, err := client.InProject(99).StoryActivity(560, query)
			Ω(activities).Should(HaveLen(4))
			Ω(err).ToNot(HaveOccurred())
		})
	})

	Describe("delivering a story", func() {
		It("HTTP PUTs it in its place", func() {
			server.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("PUT", "/services/v5/projects/99/stories/15225523"),
					ghttp.VerifyJSON(`{"current_state":"delivered"}`),
					verifyTrackerToken(),

					ghttp.RespondWith(http.StatusOK, ""),
				),
			)

			client := tracker.NewClient("api-token")

			err := client.InProject(99).DeliverStory(15225523)
			Ω(err).ShouldNot(HaveOccurred())
		})

		It("HTTP PUTs it in its place with a comment", func() {
			server.AppendHandlers(
				ghttp.CombineHandlers(
예제 #24
0
		)

		BeforeEach(func() {
			taskID = 1234
			text = "some text"
		})

		It("performs GET requests with correct headers to /task_comments", func() {
			server.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("POST", "/task_comments"),
					ghttp.VerifyHeader(http.Header{
						"X-Access-Token": []string{dummyAccessToken},
						"X-Client-ID":    []string{dummyClientID},
					}),
					ghttp.VerifyJSON(`{"task_id":1234,"text":"some text"}`),
				),
			)

			client.CreateTaskComment(text, taskID)

			Expect(server.ReceivedRequests()).Should(HaveLen(1))
		})

		Context("when the request is valid", func() {
			It("returns successfully", func() {
				expectedTaskComment := wl.TaskComment{ID: 1234}

				// Marshal and unmarshal to ensure exact object is returned
				// - this avoids odd behavior with the time fields
				expectedBody, err := json.Marshal(expectedTaskComment)
예제 #25
0
파일: quotas_test.go 프로젝트: jsloyer/cli
		It("defaults missing app instance limit to -1 (unlimited)", func() {
			Expect(quotas[1].AppInstanceLimit).To(Equal(-1))
		})

		It("defaults missing reserved route ports to be empty", func() {
			Expect(quotas[1].ReservedRoutePorts).To(BeEmpty())
		})
	})

	Describe("AssignQuotaToOrg", func() {
		BeforeEach(func() {
			ccServer.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("PUT", "/v2/organizations/my-org-guid"),
					ghttp.VerifyJSON(`{"quota_definition_guid":"my-quota-guid"}`),
					ghttp.RespondWith(http.StatusCreated, nil),
				),
			)
		})

		It("sets the quota for an organization", func() {
			err := repo.AssignQuotaToOrg("my-org-guid", "my-quota-guid")
			Expect(ccServer.ReceivedRequests()).To(HaveLen(1))
			Expect(err).NotTo(HaveOccurred())
		})
	})

	Describe("Create", func() {
		BeforeEach(func() {
			ccServer.AppendHandlers(
예제 #26
0
		BeforeEach(func() {
			date = "2013-08-30T08:29:46.203Z"
			taskID = 1234
			createdByDeviceUdid = "some device"
		})

		It("performs POST requests with correct headers to /reminders/:id", func() {
			server.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("POST", "/reminders"),
					ghttp.VerifyHeader(http.Header{
						"X-Access-Token": []string{dummyAccessToken},
						"X-Client-ID":    []string{dummyClientID},
					}),
					ghttp.VerifyJSON(`{"task_id":1234,"created_by_device_udid":"some device","date":"2013-08-30T08:29:46.203Z"}`),
				),
			)

			client.CreateReminder(date, taskID, createdByDeviceUdid)

			Expect(server.ReceivedRequests()).Should(HaveLen(1))
		})

		Context("when the request is valid", func() {
			It("returns successfully", func() {
				expectedReminder := wl.Reminder{ID: 2345}

				// Marshal and unmarshal to ensure exact object is returned
				// - this avoids odd behavior with the time fields
				expectedBody, err := json.Marshal(expectedReminder)
		It("lists the environment variables in the staging group", func() {
			envVars, err := repo.ListStaging()
			Expect(err).NotTo(HaveOccurred())
			Expect(envVars).To(ConsistOf([]models.EnvironmentVariable{
				{Name: "abc", Value: "123"},
				{Name: "do-re-mi", Value: "fa-sol-la-ti"},
			}))
		})
	})

	Describe("SetStaging", func() {
		BeforeEach(func() {
			ccServer.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("PUT", "/v2/config/environment_variable_groups/staging"),
					ghttp.VerifyJSON(`{ "abc": "one-two-three", "def": 456 }`),
					ghttp.RespondWith(http.StatusOK, nil),
				),
			)
		})

		It("sets the environment variables in the staging group", func() {
			err := repo.SetStaging(`{"abc": "one-two-three", "def": 456}`)
			Expect(err).NotTo(HaveOccurred())
			Expect(ccServer.ReceivedRequests()).To(HaveLen(1))
		})
	})

	Describe("SetRunning", func() {
		BeforeEach(func() {
			ccServer.AppendHandlers(
예제 #28
0
		)

		BeforeEach(func() {
			title = "folder title"
			listIDs = []uint{1234, 5678}
		})

		It("performs POST requests with correct headers to /folders", func() {
			server.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("POST", "/folders"),
					ghttp.VerifyHeader(http.Header{
						"X-Access-Token": []string{dummyAccessToken},
						"X-Client-ID":    []string{dummyClientID},
					}),
					ghttp.VerifyJSON(`{"list_ids":[1234,5678],"title":"folder title"}`),
				),
			)

			client.CreateFolder(
				title,
				listIDs,
			)

			Expect(server.ReceivedRequests()).Should(HaveLen(1))
		})

		Context("when the request is valid", func() {
			It("returns successfully", func() {
				expectedFolder := wl.Folder{ID: 2345}
예제 #29
0
파일: main_test.go 프로젝트: cfibmers/nsync
							"token": {},
							"task_states": [
								{
									"task_guid": "task-guid-1",
									"state": "RUNNING",
									"completion_callback": "`+fmt.Sprintf("%s/internal/v3/tasks/task-guid-1/completed", fakeCC.URL())+`"
								}
							]
						}`),
						)

						fakeCC.RouteToHandler("POST", "/internal/v3/tasks/task-guid-1/completed",
							ghttp.CombineHandlers(
								ghttp.VerifyJSON(`{
								"task_guid": "task-guid-1",
								"failed": true,
								"failure_reason": "Unable to determine completion status"
							}`),
								ghttp.RespondWith(200, `{}`),
							),
						)

						fakeBBS.RouteToHandler("POST", "/v1/tasks/list.r1",
							ghttp.RespondWith(200, `{"error": {},"tasks": []}`),
						)

						fakeBBS.RouteToHandler("POST", "/v1/desired_lrp_scheduling_infos/list",
							ghttp.RespondWith(200, `{"error":{},"desired_lrp_scheduling_infos":	[]}`),
						)

						fakeBBS.RouteToHandler("POST", "/v1/domains/upsert",
예제 #30
0
			gateway := net.NewCloudControllerGateway(configRepo, time.Now, new(terminalfakes.FakeUI), new(tracefakes.FakePrinter), "")
			repo = NewCloudControllerServiceBrokerRepository(configRepo, gateway)
		})

		AfterEach(func() {
			ccServer.Close()
		})

		It("creates the service broker with the given name, URL, username and password", func() {
			ccServer.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("POST", "/v2/service_brokers"),
					ghttp.VerifyJSON(`
						{
						    "name": "foobroker",
						    "broker_url": "http://example.com",
						    "auth_username": "******",
						    "auth_password": "******"
						}
					`),
					ghttp.RespondWith(http.StatusCreated, nil),
				),
			)

			err := repo.Create("foobroker", "http://example.com", "foouser", "password", "")
			Expect(err).NotTo(HaveOccurred())
			Expect(ccServer.ReceivedRequests()).To(HaveLen(1))
		})

		It("creates the service broker with the correct params when given a space GUID", func() {
			ccServer.AppendHandlers(
				ghttp.CombineHandlers(