-
Notifications
You must be signed in to change notification settings - Fork 931
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,556 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package v7action | ||
|
||
import ( | ||
"code.cloudfoundry.org/cli/resources" | ||
"code.cloudfoundry.org/cli/types" | ||
) | ||
|
||
func (actor *Actor) GetRevisionAnnotations(revisionGUID string) (map[string]types.NullString, Warnings, error) { | ||
resource, warnings, err := actor.GetRevisionByGUID(revisionGUID) | ||
return actor.extractAnnotations(resource.Metadata, warnings, err) | ||
} | ||
|
||
func (actor *Actor) extractAnnotations(metadata *resources.Metadata, warnings Warnings, err error) (map[string]types.NullString, Warnings, error) { | ||
var annotations map[string]types.NullString | ||
|
||
if err != nil { | ||
return annotations, warnings, err | ||
} | ||
if metadata != nil { | ||
annotations = metadata.Annotations | ||
} | ||
return annotations, warnings, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package v7action_test | ||
|
||
import ( | ||
"errors" | ||
|
||
. "code.cloudfoundry.org/cli/actor/v7action" | ||
"code.cloudfoundry.org/cli/actor/v7action/v7actionfakes" | ||
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" | ||
"code.cloudfoundry.org/cli/resources" | ||
"code.cloudfoundry.org/cli/types" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("annotations", func() { | ||
var ( | ||
actor *Actor | ||
fakeCloudControllerClient *v7actionfakes.FakeCloudControllerClient | ||
fakeSharedActor *v7actionfakes.FakeSharedActor | ||
fakeConfig *v7actionfakes.FakeConfig | ||
warnings Warnings | ||
executeErr error | ||
annotations map[string]types.NullString | ||
) | ||
|
||
BeforeEach(func() { | ||
fakeCloudControllerClient = new(v7actionfakes.FakeCloudControllerClient) | ||
fakeSharedActor = new(v7actionfakes.FakeSharedActor) | ||
fakeConfig = new(v7actionfakes.FakeConfig) | ||
actor = NewActor(fakeCloudControllerClient, fakeConfig, fakeSharedActor, nil, nil, nil) | ||
}) | ||
|
||
Describe("GetRevisionAnnotations", func() { | ||
JustBeforeEach(func() { | ||
annotations, warnings, executeErr = actor.GetRevisionAnnotations("some-guid") | ||
}) | ||
|
||
When("there are no client errors", func() { | ||
BeforeEach(func() { | ||
fakeCloudControllerClient.GetRevisionReturns( | ||
resources.Revision{GUID: "some-guid"}, | ||
ccv3.Warnings([]string{"warning-1", "warning-2"}), | ||
nil, | ||
) | ||
}) | ||
|
||
It("gets the revision", func() { | ||
Expect(fakeCloudControllerClient.GetRevisionCallCount()).To(Equal(1)) | ||
Expect(fakeCloudControllerClient.GetRevisionArgsForCall(0)).To(Equal("some-guid")) | ||
}) | ||
|
||
When("there are no annotations on a revision", func() { | ||
It("returns an empty map", func() { | ||
Expect(executeErr).NotTo(HaveOccurred()) | ||
Expect(warnings).To(ConsistOf("warning-1", "warning-2")) | ||
Expect(annotations).To(BeEmpty()) | ||
}) | ||
}) | ||
|
||
When("there are annotations", func() { | ||
var expectedAnnotations map[string]types.NullString | ||
|
||
BeforeEach(func() { | ||
expectedAnnotations = map[string]types.NullString{"key1": types.NewNullString("value1"), "key2": types.NewNullString("value2")} | ||
fakeCloudControllerClient.GetRevisionReturns( | ||
resources.Revision{ | ||
GUID: "some-guid", | ||
Metadata: &resources.Metadata{ | ||
Annotations: expectedAnnotations, | ||
}, | ||
}, | ||
ccv3.Warnings([]string{"warning-1", "warning-2"}), | ||
nil, | ||
) | ||
}) | ||
It("returns the annotations", func() { | ||
Expect(executeErr).NotTo(HaveOccurred()) | ||
Expect(warnings).To(ConsistOf("warning-1", "warning-2")) | ||
Expect(annotations).To(Equal(expectedAnnotations)) | ||
}) | ||
}) | ||
}) | ||
|
||
When("there is a client error", func() { | ||
BeforeEach(func() { | ||
fakeCloudControllerClient.GetRevisionReturns( | ||
resources.Revision{GUID: "some-guid"}, | ||
ccv3.Warnings([]string{"warning-1", "warning-2"}), | ||
errors.New("get-revision-error"), | ||
) | ||
}) | ||
When("GetRevision fails", func() { | ||
It("returns the error and all warnings", func() { | ||
Expect(executeErr).To(HaveOccurred()) | ||
Expect(warnings).To(ConsistOf("warning-1", "warning-2")) | ||
Expect(executeErr).To(MatchError("get-revision-error")) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package v7action | ||
|
||
import "code.cloudfoundry.org/cli/resources" | ||
|
||
func (actor Actor) GetRevisionByGUID(revisionGUID string) (resources.Revision, Warnings, error) { | ||
revision, warnings, err := actor.CloudControllerClient.GetRevision(revisionGUID) | ||
if err != nil { | ||
return resources.Revision{}, Warnings(warnings), err | ||
} | ||
|
||
return resources.Revision(revision), Warnings(warnings), err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package v7action_test | ||
|
||
import ( | ||
"errors" | ||
|
||
. "code.cloudfoundry.org/cli/actor/v7action" | ||
"code.cloudfoundry.org/cli/actor/v7action/v7actionfakes" | ||
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" | ||
"code.cloudfoundry.org/cli/resources" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Revision Actions", func() { | ||
Describe("GetRevisionByGUID", func() { | ||
var ( | ||
actor *Actor | ||
fakeCloudControllerClient *v7actionfakes.FakeCloudControllerClient | ||
fakeConfig *v7actionfakes.FakeConfig | ||
revisionGUID string | ||
fetchedRevision resources.Revision | ||
executeErr error | ||
warnings Warnings | ||
) | ||
|
||
BeforeEach(func() { | ||
fakeCloudControllerClient = new(v7actionfakes.FakeCloudControllerClient) | ||
fakeConfig = new(v7actionfakes.FakeConfig) | ||
actor = NewActor(fakeCloudControllerClient, fakeConfig, nil, nil, nil, nil) | ||
revisionGUID = "revision-guid" | ||
fakeConfig.APIVersionReturns("3.86.0") | ||
}) | ||
|
||
JustBeforeEach(func() { | ||
fetchedRevision, warnings, executeErr = actor.GetRevisionByGUID(revisionGUID) | ||
}) | ||
|
||
When("finding the revision fails", func() { | ||
BeforeEach(func() { | ||
fakeCloudControllerClient.GetRevisionReturns( | ||
resources.Revision{}, | ||
ccv3.Warnings{"get-revision-warning"}, | ||
errors.New("get-revision-error"), | ||
) | ||
}) | ||
|
||
It("returns an executeError", func() { | ||
Expect(executeErr).To(MatchError("get-revision-error")) | ||
Expect(warnings).To(ConsistOf("get-revision-warning")) | ||
}) | ||
}) | ||
|
||
When("finding the revision succeeds", func() { | ||
BeforeEach(func() { | ||
fakeCloudControllerClient.GetRevisionReturns( | ||
resources.Revision{GUID: "1", Deployable: true, Droplet: resources.Droplet{GUID: "droplet-guid-1"}}, | ||
nil, | ||
nil, | ||
) | ||
}) | ||
|
||
It("returns the revision", func() { | ||
Expect(fakeCloudControllerClient.GetRevisionCallCount()).To(Equal(1), "GetRevision call count") | ||
Expect(fakeCloudControllerClient.GetRevisionArgsForCall(0)).To(Equal(revisionGUID)) | ||
|
||
Expect(fetchedRevision).To(Equal( | ||
resources.Revision{GUID: "1", Deployable: true, Droplet: resources.Droplet{GUID: "droplet-guid-1"}})) | ||
Expect(executeErr).ToNot(HaveOccurred()) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.