-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OCM-2373 | feat: Added GetRole to common library
- Loading branch information
den-rgb
committed
Oct 12, 2023
1 parent
f1f61c8
commit 7b18db4
Showing
5 changed files
with
136 additions
and
0 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
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,18 @@ | ||
package validations | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/iam" | ||
"github.com/aws/aws-sdk-go/service/iam/iamiface" | ||
) | ||
|
||
func GetRole(client iamiface.IAMAPI, roleName string) (*iam.GetRoleOutput, error) { | ||
role, err := client.GetRole(&iam.GetRoleInput{ | ||
RoleName: aws.String(roleName), | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return role, 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,61 @@ | ||
package validations | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/iam" | ||
"github.com/golang/mock/gomock" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/openshift/rosa/pkg/aws/mocks" | ||
) | ||
|
||
var _ = Describe("GetRole", func() { | ||
var ( | ||
mockCtrl *gomock.Controller | ||
mockIamAPI *mocks.MockIAMAPI | ||
) | ||
|
||
BeforeEach(func() { | ||
mockCtrl = gomock.NewController(GinkgoT()) | ||
mockIamAPI = mocks.NewMockIAMAPI(mockCtrl) | ||
}) | ||
|
||
|
||
AfterEach(func() { | ||
mockCtrl.Finish() | ||
}) | ||
|
||
Context("When IAM client returns a role", func() { | ||
BeforeEach(func() { | ||
mockIamAPI .EXPECT().GetRole(gomock.Any()).Return(&iam.GetRoleOutput{ | ||
Role: &iam.Role{ | ||
RoleName: aws.String("role-name"), | ||
}, | ||
}, nil) | ||
}) | ||
|
||
It("should return the role", func() { | ||
role, err := GetRole(mockIamAPI, "role-name") | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(role).To(Equal(&iam.GetRoleOutput{ | ||
Role: &iam.Role{ | ||
RoleName: aws.String("role-name"), | ||
}, | ||
})) | ||
}) | ||
}) | ||
|
||
Context("When IAM client returns an error", func() { | ||
BeforeEach(func() { | ||
mockIamAPI.EXPECT().GetRole(gomock.Any()).Return(nil, errors.New("some-error")) | ||
}) | ||
|
||
It("should return the error", func() { | ||
role, err := GetRole(mockIamAPI, "role-name") | ||
Expect(err).To(HaveOccurred()) | ||
Expect(role).To(BeNil()) | ||
}) | ||
}) | ||
}) |
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,13 @@ | ||
package validations | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestValidations(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Validations Suite") | ||
} |