-
Notifications
You must be signed in to change notification settings - Fork 3
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
2 changed files
with
182 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package tokensettings_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cyralinc/terraform-provider-cyral/cyral/internal/tokensettings" | ||
"github.com/cyralinc/terraform-provider-cyral/cyral/provider" | ||
"github.com/cyralinc/terraform-provider-cyral/cyral/utils" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
const ( | ||
completeDataSourceName = "data." + completeResourceName | ||
) | ||
|
||
func TestAccAccessTokenSettingsDataSource(t *testing.T) { | ||
testSteps := []resource.TestStep{ | ||
{ | ||
Config: testAccAccessTokenSettingsDataSourceConfig(), | ||
Check: testAccAccessTokenSettingsDataSourceCheck(), | ||
}, | ||
} | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
ProviderFactories: provider.ProviderFactories, | ||
Steps: testSteps, | ||
}) | ||
} | ||
|
||
func testAccAccessTokenSettingsDataSourceConfig() string { | ||
return ` | ||
data "cyral_access_token_settings" "token_settings" { | ||
} | ||
` | ||
} | ||
|
||
func testAccAccessTokenSettingsDataSourceCheck() resource.TestCheckFunc { | ||
testCheckFuncs := []resource.TestCheckFunc{ | ||
resource.TestCheckResourceAttrSet(completeDataSourceName, utils.IDKey), | ||
resource.TestCheckResourceAttrSet(completeDataSourceName, tokensettings.MaxValidityKey), | ||
resource.TestCheckResourceAttrSet(completeDataSourceName, tokensettings.DefaultValidityKey), | ||
resource.TestCheckResourceAttrSet(completeDataSourceName, tokensettings.MaxNumberOfTokensPerUserKey), | ||
resource.TestCheckResourceAttrSet(completeDataSourceName, tokensettings.OfflineTokenValidationKey), | ||
} | ||
return resource.ComposeTestCheckFunc( | ||
testCheckFuncs..., | ||
) | ||
} |
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,134 @@ | ||
package tokensettings_test | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/cyralinc/terraform-provider-cyral/cyral/internal/tokensettings" | ||
"github.com/cyralinc/terraform-provider-cyral/cyral/provider" | ||
"github.com/cyralinc/terraform-provider-cyral/cyral/utils" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
const ( | ||
resourceName = "token_settings" | ||
completeResourceName = "cyral_access_token_settings." + resourceName | ||
) | ||
|
||
func TestAccAccessTokenSettingsResource(t *testing.T) { | ||
testSteps := []resource.TestStep{} | ||
testSteps = append(testSteps, getRequiredArgumentTestSteps()...) | ||
testSteps = append( | ||
testSteps, | ||
[]resource.TestStep{ | ||
{ | ||
Config: testAccAccessTokenSettingsConfig_OnlyRequiredArguments(accessTokenSettingsOnlyRequiredArguments), | ||
Check: testAccAccessTokenSettingsCheck(accessTokenSettingsOnlyRequiredArguments), | ||
}, | ||
{ | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ResourceName: completeResourceName, | ||
}, | ||
}..., | ||
) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
ProviderFactories: provider.ProviderFactories, | ||
Steps: testSteps, | ||
}) | ||
} | ||
|
||
func getRequiredArgumentTestSteps() []resource.TestStep { | ||
requiredArgumentsTestSteps := []resource.TestStep{} | ||
requiredArguments := []string{ | ||
tokensettings.MaxValidityKey, | ||
tokensettings.DefaultValidityKey, | ||
tokensettings.MaxNumberOfTokensPerUserKey, | ||
tokensettings.OfflineTokenValidationKey, | ||
} | ||
for _, argument := range requiredArguments { | ||
requiredArgumentsTestSteps = append(requiredArgumentsTestSteps, resource.TestStep{ | ||
Config: testAccAccessTokenSettingsConfig_EmptyConfig(), | ||
ExpectError: regexp.MustCompile( | ||
fmt.Sprintf(`The argument "%s" is required`, argument), | ||
), | ||
}) | ||
} | ||
return requiredArgumentsTestSteps | ||
} | ||
|
||
func testAccAccessTokenSettingsConfig_EmptyConfig() string { | ||
return ` | ||
resource "cyral_access_token_settings" "token_settings" { | ||
} | ||
` | ||
} | ||
|
||
type AccessTokenSettingsTestParameters struct { | ||
settings tokensettings.AccessTokenSettings | ||
} | ||
|
||
var ( | ||
accessTokenSettingsOnlyRequiredArguments = AccessTokenSettingsTestParameters{ | ||
settings: tokensettings.AccessTokenSettings{ | ||
MaxValidity: "18000s", | ||
DefaultValidity: "300s", | ||
MaxNumberOfTokensPerUser: 5, | ||
OfflineTokenValidation: false, | ||
}, | ||
} | ||
) | ||
|
||
func testAccAccessTokenSettingsConfig_OnlyRequiredArguments( | ||
parameters AccessTokenSettingsTestParameters, | ||
) string { | ||
return fmt.Sprintf(` | ||
resource "cyral_access_token_settings" "token_settings" { | ||
max_validity = %q | ||
default_validity = %q | ||
max_number_of_tokens_per_user = %d | ||
offline_token_validation = %t | ||
} | ||
`, | ||
parameters.settings.MaxValidity, | ||
parameters.settings.DefaultValidity, | ||
parameters.settings.MaxNumberOfTokensPerUser, | ||
parameters.settings.OfflineTokenValidation, | ||
) | ||
} | ||
|
||
func testAccAccessTokenSettingsCheck( | ||
parameters AccessTokenSettingsTestParameters, | ||
) resource.TestCheckFunc { | ||
testCheckFuncs := []resource.TestCheckFunc{ | ||
resource.TestCheckResourceAttrSet(completeResourceName, utils.IDKey), | ||
resource.TestCheckResourceAttr( | ||
completeResourceName, | ||
tokensettings.MaxValidityKey, | ||
parameters.settings.MaxValidity, | ||
), | ||
resource.TestCheckResourceAttrSet(completeResourceName, utils.IDKey), | ||
resource.TestCheckResourceAttr( | ||
completeResourceName, | ||
tokensettings.DefaultValidityKey, | ||
parameters.settings.DefaultValidity, | ||
), | ||
resource.TestCheckResourceAttrSet(completeResourceName, utils.IDKey), | ||
resource.TestCheckResourceAttr( | ||
completeResourceName, | ||
tokensettings.MaxNumberOfTokensPerUserKey, | ||
fmt.Sprintf("%d", parameters.settings.MaxNumberOfTokensPerUser), | ||
), | ||
resource.TestCheckResourceAttrSet(completeResourceName, utils.IDKey), | ||
resource.TestCheckResourceAttr( | ||
completeResourceName, | ||
tokensettings.OfflineTokenValidationKey, | ||
fmt.Sprintf("%t", parameters.settings.OfflineTokenValidation), | ||
), | ||
} | ||
return resource.ComposeTestCheckFunc( | ||
testCheckFuncs..., | ||
) | ||
} |