Skip to content

Commit

Permalink
add UT for IRSA datamodel convertors
Browse files Browse the repository at this point in the history
  • Loading branch information
nithyatsu committed Jul 10, 2024
1 parent 2aee7f2 commit c3910f5
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
54 changes: 53 additions & 1 deletion pkg/ucp/api/v20231001preview/aws_credential_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/stretchr/testify/require"
)

func TestAWSAccessKeyCredentialConvertVersionedToDataModel(t *testing.T) {
func TestAWSCredentialConvertVersionedToDataModel(t *testing.T) {
conversionTests := []struct {
filename string
expected *datamodel.AWSCredential
Expand Down Expand Up @@ -68,6 +68,38 @@ func TestAWSAccessKeyCredentialConvertVersionedToDataModel(t *testing.T) {
},
},
},
{
filename: "credentialresource-aws-irsa.json",
expected: &datamodel.AWSCredential{
BaseResource: v1.BaseResource{
TrackedResource: v1.TrackedResource{
ID: "/planes/aws/aws/providers/System.AWS/credentials/default",
Name: "default",
Type: "System.AWS/credentials",
Location: "west-us-2",
Tags: map[string]string{
"env": "dev",
},
},
InternalMetadata: v1.InternalMetadata{
UpdatedAPIVersion: Version,
},
},
Properties: &datamodel.AWSCredentialResourceProperties{
Kind: "IRSA",
AWSCredential: &datamodel.AWSCredentialProperties{
Kind: datamodel.AWSIRSACredentialKind,
IRSACredential: &datamodel.AWSIRSACredentialProperties{
RoleARN: "arn:aws:iam::000000000000:role/role-name",
},
},
Storage: &datamodel.CredentialStorageProperties{
Kind: datamodel.InternalStorageKind,
InternalCredential: &datamodel.InternalCredentialStorageProperties{},
},
},
},
},
{
filename: "credentialresource-other.json",
err: v1.ErrInvalidModelConversion,
Expand Down Expand Up @@ -135,6 +167,26 @@ func TestAWSAccessKeyCredentialConvertDataModelToVersioned(t *testing.T) {
},
},
},
{
filename: "credentialresourcedatamodel-aws-irsa.json",
expected: &AwsCredentialResource{
ID: to.Ptr("/planes/aws/aws/providers/System.AWS/credentials/default"),
Name: to.Ptr("default"),
Type: to.Ptr("System.AWS/credentials"),
Location: to.Ptr("west-us-2"),
Tags: map[string]*string{
"env": to.Ptr("dev"),
},
Properties: &AwsIRSACredentialProperties{
Kind: to.Ptr(AWSCredentialKindIRSA),
RoleARN: to.Ptr("arn:aws:iam::000000000000:role/role-name"),
Storage: &InternalCredentialStorageProperties{
Kind: to.Ptr(CredentialStorageKindInternal),
SecretName: to.Ptr("aws-awscloud-default"),
},
},
},
},
{
filename: "credentialresourcedatamodel-default.json",
err: v1.ErrInvalidModelConversion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"properties": {
"roleARN": "arn:aws:iam::000000000000:role/role-name",
"kind": "AccessKey",
"kind": "IRSA",
"storage": {
"kind": "Internal"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"awsCredential": {
"kind": "IRSA",
"irsa": {
"roleARN": "arn:aws:iam::123456789012:role/role-name"
"roleARN": "arn:aws:iam::000000000000:role/role-name"
}
},
"storage": {
Expand Down

0 comments on commit c3910f5

Please sign in to comment.