@@ -23,13 +23,20 @@ import (
2323 "github.com/hashicorp/terraform-plugin-testing/terraform"
2424)
2525
26- func TestAccessTokenResource (t * testing.T ) {
26+ func TestAccessTokenResource_WithExpires (t * testing.T ) {
27+ config := `
28+ resource "docker_access_token" "test" {
29+ token_label = "test-label"
30+ scopes = ["repo:read", "repo:write"]
31+ expires_at = "2029-12-31T23:59:59Z"
32+ }
33+ `
2734 resource .Test (t , resource.TestCase {
2835 PreCheck : func () { testAccPreCheck (t ) },
2936 ProtoV6ProviderFactories : testAccProtoV6ProviderFactories ,
3037 Steps : []resource.TestStep {
3138 {
32- Config : testAccessTokenResourceConfig ,
39+ Config : config ,
3340 Check : resource .ComposeAggregateTestCheckFunc (
3441 resource .TestCheckResourceAttrSet ("docker_access_token.test" , "uuid" ),
3542 resource .TestCheckResourceAttr ("docker_access_token.test" , "is_active" , "true" ),
@@ -55,13 +62,43 @@ func TestAccessTokenResource(t *testing.T) {
5562 })
5663}
5764
58- const testAccessTokenResourceConfig = `
65+ func TestAccessTokenResource_NoExpires (t * testing.T ) {
66+ config := `
5967resource "docker_access_token" "test" {
6068 token_label = "test-label"
61- scopes = ["repo:read", "repo:write"]
62- expires_at = "2029-12-31T23:59:59Z"
69+ scopes = ["repo:read"]
6370}
6471`
72+ resource .Test (t , resource.TestCase {
73+ PreCheck : func () { testAccPreCheck (t ) },
74+ ProtoV6ProviderFactories : testAccProtoV6ProviderFactories ,
75+ Steps : []resource.TestStep {
76+ {
77+ Config : config ,
78+ Check : resource .ComposeAggregateTestCheckFunc (
79+ resource .TestCheckResourceAttrSet ("docker_access_token.test" , "uuid" ),
80+ resource .TestCheckResourceAttr ("docker_access_token.test" , "is_active" , "true" ),
81+ resource .TestCheckResourceAttr ("docker_access_token.test" , "token_label" , "test-label" ),
82+ resource .TestCheckResourceAttr ("docker_access_token.test" , "scopes.#" , "1" ),
83+ resource .TestCheckResourceAttrSet ("docker_access_token.test" , "token" ), // Check if the token is set
84+ resource .TestCheckNoResourceAttr ("docker_access_token.test" , "expires_at" ),
85+ ),
86+ },
87+ {
88+ ResourceName : "docker_access_token.test" ,
89+ ImportState : true ,
90+ ImportStateVerify : true ,
91+ ImportStateVerifyIdentifierAttribute : "uuid" ,
92+ ImportStateVerifyIgnore : []string {
93+ "token" , // Ignore the token attribute during import state verification
94+ },
95+ ImportStateIdFunc : func (state * terraform.State ) (string , error ) {
96+ return state .RootModule ().Resources ["docker_access_token.test" ].Primary .Attributes ["uuid" ], nil
97+ },
98+ },
99+ },
100+ })
101+ }
65102
66103func TestAccessTokenResource_Upgrade (t * testing.T ) {
67104 config := `
0 commit comments