From c3910f5fec0062112765e6730a10397b906d0d51 Mon Sep 17 00:00:00 2001 From: nithyatsu Date: Wed, 10 Jul 2024 15:48:09 -0700 Subject: [PATCH] add UT for IRSA datamodel convertors --- .../aws_credential_conversion_test.go | 54 ++++++++++++++++++- .../testdata/credentialresource-aws-irsa.json | 2 +- .../credentialresourcedatamodel-aws-irsa.json | 2 +- 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/pkg/ucp/api/v20231001preview/aws_credential_conversion_test.go b/pkg/ucp/api/v20231001preview/aws_credential_conversion_test.go index ce94b6f0de..3051abc97d 100644 --- a/pkg/ucp/api/v20231001preview/aws_credential_conversion_test.go +++ b/pkg/ucp/api/v20231001preview/aws_credential_conversion_test.go @@ -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 @@ -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, @@ -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, diff --git a/pkg/ucp/api/v20231001preview/testdata/credentialresource-aws-irsa.json b/pkg/ucp/api/v20231001preview/testdata/credentialresource-aws-irsa.json index b514808879..421a43d58b 100644 --- a/pkg/ucp/api/v20231001preview/testdata/credentialresource-aws-irsa.json +++ b/pkg/ucp/api/v20231001preview/testdata/credentialresource-aws-irsa.json @@ -8,7 +8,7 @@ }, "properties": { "roleARN": "arn:aws:iam::000000000000:role/role-name", - "kind": "AccessKey", + "kind": "IRSA", "storage": { "kind": "Internal" } diff --git a/pkg/ucp/api/v20231001preview/testdata/credentialresourcedatamodel-aws-irsa.json b/pkg/ucp/api/v20231001preview/testdata/credentialresourcedatamodel-aws-irsa.json index defbbd4b91..efb56f8e8d 100644 --- a/pkg/ucp/api/v20231001preview/testdata/credentialresourcedatamodel-aws-irsa.json +++ b/pkg/ucp/api/v20231001preview/testdata/credentialresourcedatamodel-aws-irsa.json @@ -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": {