Ejemplo n.º 1
0
func TestDeleteBuildpackThatDoesNotExist(t *testing.T) {
	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true}
	buildpack := cf.Buildpack{}
	buildpack.Name = "my-buildpack"
	buildpack.Guid = "my-buildpack-guid"
	buildpackRepo := &testapi.FakeBuildpackRepository{
		FindByNameNotFound:  true,
		FindByNameBuildpack: buildpack,
	}

	ui := &testterm.FakeUI{}
	ctxt := testcmd.NewContext("delete-buildpack", []string{"-f", "my-buildpack"})

	cmd := NewDeleteBuildpack(ui, buildpackRepo)
	testcmd.RunCommand(cmd, ctxt, reqFactory)

	assert.Equal(t, buildpackRepo.FindByNameName, "my-buildpack")
	assert.True(t, buildpackRepo.FindByNameNotFound)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Deleting", "my-buildpack"},
		{"OK"},
		{"my-buildpack", "does not exist"},
	})
}
Ejemplo n.º 2
0
func TestDeleteBuildpackSuccess(t *testing.T) {
	ui := &testterm.FakeUI{Inputs: []string{"y"}}
	buildpack := cf.Buildpack{}
	buildpack.Name = "my-buildpack"
	buildpack.Guid = "my-buildpack-guid"
	buildpackRepo := &testapi.FakeBuildpackRepository{
		FindByNameBuildpack: buildpack,
	}
	cmd := NewDeleteBuildpack(ui, buildpackRepo)

	ctxt := testcmd.NewContext("delete-buildpack", []string{"my-buildpack"})
	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true}

	testcmd.RunCommand(cmd, ctxt, reqFactory)

	assert.Equal(t, buildpackRepo.DeleteBuildpackGuid, "my-buildpack-guid")

	testassert.SliceContains(t, ui.Prompts, testassert.Lines{
		{"delete", "my-buildpack"},
	})
	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Deleting buildpack", "my-buildpack"},
		{"OK"},
	})
}
Ejemplo n.º 3
0
func TestDeleteBuildpackDeleteError(t *testing.T) {
	ui := &testterm.FakeUI{Inputs: []string{"y"}}
	buildpack := cf.Buildpack{}
	buildpack.Name = "my-buildpack"
	buildpack.Guid = "my-buildpack-guid"
	buildpackRepo := &testapi.FakeBuildpackRepository{
		FindByNameBuildpack: buildpack,
		DeleteApiResponse:   net.NewApiResponseWithMessage("failed badly"),
	}

	cmd := NewDeleteBuildpack(ui, buildpackRepo)

	ctxt := testcmd.NewContext("delete-buildpack", []string{"my-buildpack"})
	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true}

	testcmd.RunCommand(cmd, ctxt, reqFactory)

	assert.Equal(t, buildpackRepo.DeleteBuildpackGuid, "my-buildpack-guid")

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Deleting buildpack", "my-buildpack"},
		{"FAILED"},
		{"my-buildpack"},
		{"failed badly"},
	})
}
Ejemplo n.º 4
0
func TestBuildpackReqExecute(t *testing.T) {
	buildpack := cf.Buildpack{}
	buildpack.Name = "my-buildpack"
	buildpack.Guid = "my-buildpack-guid"
	buildpackRepo := &testapi.FakeBuildpackRepository{FindByNameBuildpack: buildpack}
	ui := new(testterm.FakeUI)

	buildpackReq := newBuildpackRequirement("foo", ui, buildpackRepo)
	success := buildpackReq.Execute()

	assert.True(t, success)
	assert.Equal(t, buildpackRepo.FindByNameName, "foo")
	assert.Equal(t, buildpackReq.GetBuildpack(), buildpack)
}
Ejemplo n.º 5
0
func TestBuildpacksFindByName(t *testing.T) {
	req := testapi.NewCloudControllerTestRequest(findBuildpackRequest)

	ts, handler, repo := createBuildpackRepo(t, req)
	defer ts.Close()
	existingBuildpack := cf.Buildpack{}
	existingBuildpack.Guid = "buildpack1-guid"
	existingBuildpack.Name = "Buildpack1"

	buildpack, apiResponse := repo.FindByName("Buildpack1")

	assert.True(t, handler.AllRequestsCalled())
	assert.True(t, apiResponse.IsSuccessful())

	assert.Equal(t, buildpack.Name, existingBuildpack.Name)
	assert.Equal(t, buildpack.Guid, existingBuildpack.Guid)
	assert.Equal(t, *buildpack.Position, 10)
}
Ejemplo n.º 6
0
func TestUpdateBuildpack(t *testing.T) {
	req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:  "PUT",
		Path:    "/v2/buildpacks/my-cool-buildpack-guid",
		Matcher: testnet.RequestBodyMatcher(`{"name":"my-cool-buildpack","position":555,"enabled":false}`),
		Response: testnet.TestResponse{
			Status: http.StatusCreated,
			Body: `{
				    "metadata": {
				        "guid": "my-cool-buildpack-guid"
				    },
				    "entity": {
				        "name": "my-cool-buildpack",
						"position":555,
						"enabled":false
				    }
				}`},
	})

	ts, handler, repo := createBuildpackRepo(t, req)
	defer ts.Close()

	position := 555
	enabled := false
	buildpack := cf.Buildpack{}
	buildpack.Name = "my-cool-buildpack"
	buildpack.Guid = "my-cool-buildpack-guid"
	buildpack.Position = &position
	buildpack.Enabled = &enabled
	updated, apiResponse := repo.Update(buildpack)

	assert.True(t, handler.AllRequestsCalled())
	assert.False(t, apiResponse.IsNotSuccessful())

	assert.Equal(t, buildpack, updated)
}
Ejemplo n.º 7
0
func TestBuildpacksListBuildpacks(t *testing.T) {
	firstRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method: "GET",
		Path:   "/v2/buildpacks",
		Response: testnet.TestResponse{
			Status: http.StatusOK,
			Body: `{
			  "next_url": "/v2/buildpacks?page=2",
			  "resources": [
			    {
			      "metadata": {
			        "guid": "buildpack1-guid"
			      },
			      "entity": {
			        "name": "Buildpack1",
					"position" : 1
			      }
			    }
			  ]
			}`},
	})

	secondRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method: "GET",
		Path:   "/v2/buildpacks?page=2",
		Response: testnet.TestResponse{
			Status: http.StatusOK,
			Body: `{
			  "resources": [
			    {
			      "metadata": {
			        "guid": "buildpack2-guid"
			      },
			      "entity": {
			        "name": "Buildpack2",
					"position" : 2
			      }
			    }
			  ]
			}`},
	})

	ts, handler, repo := createBuildpackRepo(t, firstRequest, secondRequest)
	defer ts.Close()

	stopChan := make(chan bool)
	defer close(stopChan)
	buildpacksChan, statusChan := repo.ListBuildpacks(stopChan)

	one := 1
	buildpack := cf.Buildpack{}
	buildpack.Guid = "buildpack1-guid"
	buildpack.Name = "Buildpack1"
	buildpack.Position = &one

	two := 2
	buildpack2 := cf.Buildpack{}
	buildpack2.Guid = "buildpack2-guid"
	buildpack2.Name = "Buildpack2"
	buildpack2.Position = &two

	expectedBuildpacks := []cf.Buildpack{buildpack, buildpack2}

	buildpacks := []cf.Buildpack{}
	for chunk := range buildpacksChan {
		buildpacks = append(buildpacks, chunk...)
	}
	apiResponse := <-statusChan

	assert.Equal(t, buildpacks, expectedBuildpacks)
	assert.True(t, handler.AllRequestsCalled())
	assert.True(t, apiResponse.IsSuccessful())
}