예제 #1
0
파일: spaces_test.go 프로젝트: GABONIA/cli
func testSpacesDidNotFindByNameWithOrg(orgGuid string, findByName func(SpaceRepository, string) (models.Space, error)) {
	request := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method: "GET",
		Path:   fmt.Sprintf("/v2/organizations/%s/spaces?q=name%%3Aspace1&inline-relations-depth=1", orgGuid),
		Response: testnet.TestResponse{
			Status: http.StatusOK,
			Body:   ` { "resources": [ ] }`,
		},
	})

	ts, handler, repo := createSpacesRepo(request)
	defer ts.Close()

	_, apiErr := findByName(repo, "Space1")
	Expect(handler).To(testnet.HaveAllRequestsCalled())

	Expect(apiErr.(*errors.ModelNotFoundError)).NotTo(BeNil())
}
예제 #2
0
	Describe("Create", func() {
		Context("when the service binding can be created", func() {
			BeforeEach(func() {
				setupTestServer(testapi.NewCloudControllerTestRequest(testnet.TestRequest{
					Method:   "POST",
					Path:     "/v2/service_bindings",
					Matcher:  testnet.RequestBodyMatcher(`{"app_guid":"my-app-guid","service_instance_guid":"my-service-instance-guid","async":true}`),
					Response: testnet.TestResponse{Status: http.StatusCreated},
				}))
			})

			It("TestCreateServiceBinding", func() {
				apiErr := repo.Create("my-service-instance-guid", "my-app-guid")

				Expect(testHandler).To(testnet.HaveAllRequestsCalled())
				Expect(apiErr).NotTo(HaveOccurred())
			})
		})

		Context("when an error occurs", func() {
			BeforeEach(func() {
				setupTestServer(testapi.NewCloudControllerTestRequest(testnet.TestRequest{
					Method:  "POST",
					Path:    "/v2/service_bindings",
					Matcher: testnet.RequestBodyMatcher(`{"app_guid":"my-app-guid","service_instance_guid":"my-service-instance-guid","async":true}`),
					Response: testnet.TestResponse{
						Status: http.StatusBadRequest,
						Body:   `{"code":90003,"description":"The app space binding to service is taken: 7b959018-110a-4913-ac0a-d663e613cdea 346bf237-7eef-41a7-b892-68fb08068f09"}`,
					},
				}))
예제 #3
0
		It("fails to upload a buildpack with an invalid directory", func() {
			apiErr := repo.UploadBuildpack(buildpack, "/foo/bar")
			Expect(apiErr).NotTo(BeNil())
			Expect(apiErr.Error()).To(ContainSubstring("Error opening buildpack file"))
		})

		It("uploads a valid buildpack directory", func() {
			buildpackPath := filepath.Join(buildpacksDir, "example-buildpack")

			os.Chmod(filepath.Join(buildpackPath, "bin/compile"), 0755)
			os.Chmod(filepath.Join(buildpackPath, "bin/detect"), 0755)
			err := os.Chmod(filepath.Join(buildpackPath, "bin/release"), 0755)
			Expect(err).NotTo(HaveOccurred())

			apiErr := repo.UploadBuildpack(buildpack, buildpackPath)
			Expect(testServerHandler).To(testnet.HaveAllRequestsCalled())
			Expect(apiErr).NotTo(HaveOccurred())
		})

		It("uploads a valid zipped buildpack", func() {
			buildpackPath := filepath.Join(buildpacksDir, "example-buildpack.zip")

			apiErr := repo.UploadBuildpack(buildpack, buildpackPath)
			Expect(testServerHandler).To(testnet.HaveAllRequestsCalled())
			Expect(apiErr).NotTo(HaveOccurred())
		})

		Describe("when the buildpack is wrapped in an extra top-level directory", func() {
			It("uploads a zip file containing only the actual buildpack", func() {
				buildpackPath := filepath.Join(buildpacksDir, "example-buildpack-in-dir.zip")
예제 #4
0
파일: spaces_test.go 프로젝트: GABONIA/cli
func testSpacesFindByNameWithOrg(orgGuid string, findByName func(SpaceRepository, string) (models.Space, error)) {
	findSpaceByNameResponse := testnet.TestResponse{
		Status: http.StatusOK,
		Body: `
{
  "resources": [
    {
      "metadata": {
        "guid": "space1-guid"
      },
      "entity": {
        "name": "Space1",
        "organization_guid": "org1-guid",
        "organization": {
          "metadata": {
            "guid": "org1-guid"
          },
          "entity": {
            "name": "Org1"
          }
        },
        "apps": [
          {
            "metadata": {
              "guid": "app1-guid"
            },
            "entity": {
              "name": "app1"
            }
          },
          {
            "metadata": {
              "guid": "app2-guid"
            },
            "entity": {
              "name": "app2"
            }
          }
        ],
        "domains": [
          {
            "metadata": {
              "guid": "domain1-guid"
            },
            "entity": {
              "name": "domain1"
            }
          }
        ],
        "service_instances": [
          {
			"metadata": {
              "guid": "service1-guid"
            },
            "entity": {
              "name": "service1"
            }
          }
        ]
      }
    }
  ]
}`}
	request := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:   "GET",
		Path:     fmt.Sprintf("/v2/organizations/%s/spaces?q=name%%3Aspace1&inline-relations-depth=1", orgGuid),
		Response: findSpaceByNameResponse,
	})

	ts, handler, repo := createSpacesRepo(request)
	defer ts.Close()

	space, apiErr := findByName(repo, "Space1")
	Expect(handler).To(testnet.HaveAllRequestsCalled())
	Expect(apiErr).NotTo(HaveOccurred())
	Expect(space.Name).To(Equal("Space1"))
	Expect(space.Guid).To(Equal("space1-guid"))

	Expect(space.Organization.Guid).To(Equal("org1-guid"))

	Expect(len(space.Applications)).To(Equal(2))
	Expect(space.Applications[0].Guid).To(Equal("app1-guid"))
	Expect(space.Applications[1].Guid).To(Equal("app2-guid"))

	Expect(len(space.Domains)).To(Equal(1))
	Expect(space.Domains[0].Guid).To(Equal("domain1-guid"))

	Expect(len(space.ServiceInstances)).To(Equal(1))
	Expect(space.ServiceInstances[0].Guid).To(Equal("service1-guid"))

	Expect(apiErr).NotTo(HaveOccurred())
	return
}