From c5c91d171bb5ec09292dc8327607a906c93a9de4 Mon Sep 17 00:00:00 2001 From: Tomer Heber Date: Tue, 26 Sep 2023 19:14:31 -0500 Subject: [PATCH] updated tests --- env0/resource_cost_credentials_test.go | 30 +++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/env0/resource_cost_credentials_test.go b/env0/resource_cost_credentials_test.go index 021b0a0f..fee66e01 100644 --- a/env0/resource_cost_credentials_test.go +++ b/env0/resource_cost_credentials_test.go @@ -18,8 +18,9 @@ func TestUnitAwsCostCredentialsResource(t *testing.T) { accessor := resourceAccessor(resourceType, resourceName) awsCredentialResource := map[string]interface{}{ - "name": "test", - "arn": "11111", + "name": "test", + "arn": "11111", + "duration": 7200, } updatedAwsCredentialResource := map[string]interface{}{ @@ -28,10 +29,17 @@ func TestUnitAwsCostCredentialsResource(t *testing.T) { "duration": 3600, } + invalidDurationAwsCredentialResource := map[string]interface{}{ + "name": "update", + "arn": "33333", + "duration": 1234, + } + awsCredCreatePayload := client.AwsCredentialsCreatePayload{ Name: awsCredentialResource["name"].(string), Value: client.AwsCredentialsValuePayload{ - RoleArn: awsCredentialResource["arn"].(string), + RoleArn: awsCredentialResource["arn"].(string), + Duration: awsCredentialResource["duration"].(int), }, Type: client.AwsCostCredentialsType, } @@ -67,7 +75,7 @@ func TestUnitAwsCostCredentialsResource(t *testing.T) { resource.TestCheckResourceAttr(accessor, "name", awsCredentialResource["name"].(string)), resource.TestCheckResourceAttr(accessor, "arn", awsCredentialResource["arn"].(string)), resource.TestCheckResourceAttr(accessor, "id", "id"), - resource.TestCheckNoResourceAttr(accessor, "duration"), + resource.TestCheckResourceAttr(accessor, "duration", strconv.Itoa(awsCredentialResource["duration"].(int))), ), }, }, @@ -81,7 +89,7 @@ func TestUnitAwsCostCredentialsResource(t *testing.T) { resource.TestCheckResourceAttr(accessor, "name", awsCredentialResource["name"].(string)), resource.TestCheckResourceAttr(accessor, "arn", awsCredentialResource["arn"].(string)), resource.TestCheckResourceAttr(accessor, "id", returnValues.Id), - resource.TestCheckNoResourceAttr(accessor, "duration"), + resource.TestCheckResourceAttr(accessor, "duration", strconv.Itoa(awsCredentialResource["duration"].(int))), ), }, { @@ -135,6 +143,18 @@ func TestUnitAwsCostCredentialsResource(t *testing.T) { }) }) + t.Run("throw error when don't enter duration valid values", func(t *testing.T) { + runUnitTest(t, resource.TestCase{ + Steps: []resource.TestStep{ + { + Config: resourceConfigCreate(resourceType, resourceName, invalidDurationAwsCredentialResource), + ExpectError: regexp.MustCompile("Error: must be one of"), + }, + }, + }, func(mock *client.MockApiClientInterface) { + }) + }) + } func TestUnitAzureCostCredentialsResource(t *testing.T) {