@@ -43,14 +43,16 @@ func testSweepAccountSSHKey(region string) error {
43
43
return nil
44
44
}
45
45
46
- func TestAccScalewayAccountSSHKey (t * testing.T ) {
46
+ func TestAccScalewayAccountSSHKey_basic (t * testing.T ) {
47
47
name := newRandomName ("ssh-key" )
48
48
SSHKey := "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEEYrzDOZmhItdKaDAEqJQ4ORS2GyBMtBozYsK5kiXXX [email protected] "
49
+ tt := NewTestTools (t )
50
+ defer tt .Cleanup ()
49
51
50
52
resource .ParallelTest (t , resource.TestCase {
51
- PreCheck : func () { testAccPreCheck (t ) },
52
- Providers : testAccProviders ,
53
- CheckDestroy : testAccCheckScalewayAccountSSHKeyDestroy ,
53
+ PreCheck : func () { testAccPreCheck (t ) },
54
+ ProviderFactories : tt . ProviderFactories ,
55
+ CheckDestroy : testAccCheckScalewayAccountSSHKeyDestroy ( tt ) ,
54
56
Steps : []resource.TestStep {
55
57
{
56
58
Config : `
@@ -60,7 +62,7 @@ func TestAccScalewayAccountSSHKey(t *testing.T) {
60
62
}
61
63
` ,
62
64
Check : resource .ComposeTestCheckFunc (
63
- testAccCheckScalewayAccountSSHKeyExists ("scaleway_account_ssh_key.main" ),
65
+ testAccCheckScalewayAccountSSHKeyExists (tt , "scaleway_account_ssh_key.main" ),
64
66
resource .TestCheckResourceAttr ("scaleway_account_ssh_key.main" , "name" , name ),
65
67
resource .TestCheckResourceAttr ("scaleway_account_ssh_key.main" , "public_key" , SSHKey ),
66
68
),
@@ -73,7 +75,7 @@ func TestAccScalewayAccountSSHKey(t *testing.T) {
73
75
}
74
76
` ,
75
77
Check : resource .ComposeTestCheckFunc (
76
- testAccCheckScalewayAccountSSHKeyExists ("scaleway_account_ssh_key.main" ),
78
+ testAccCheckScalewayAccountSSHKeyExists (tt , "scaleway_account_ssh_key.main" ),
77
79
resource .TestCheckResourceAttr ("scaleway_account_ssh_key.main" , "name" , name + "-updated" ),
78
80
resource .TestCheckResourceAttr ("scaleway_account_ssh_key.main" , "public_key" , SSHKey ),
79
81
),
@@ -85,11 +87,13 @@ func TestAccScalewayAccountSSHKey(t *testing.T) {
85
87
func TestAccScalewayAccountSSHKey_WithNewLine (t * testing.T ) {
86
88
name := newRandomName ("ssh-key" )
87
89
SSHKey := "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDjfkdWCwkYlVQMDUfiZlVrmjaGOfBYnmkucssae8Iup [email protected] "
90
+ tt := NewTestTools (t )
91
+ defer tt .Cleanup ()
88
92
89
93
resource .ParallelTest (t , resource.TestCase {
90
- PreCheck : func () { testAccPreCheck (t ) },
91
- Providers : testAccProviders ,
92
- CheckDestroy : testAccCheckScalewayAccountSSHKeyDestroy ,
94
+ PreCheck : func () { testAccPreCheck (t ) },
95
+ ProviderFactories : tt . ProviderFactories ,
96
+ CheckDestroy : testAccCheckScalewayAccountSSHKeyDestroy ( tt ) ,
93
97
Steps : []resource.TestStep {
94
98
{
95
99
Config : `
@@ -99,7 +103,7 @@ func TestAccScalewayAccountSSHKey_WithNewLine(t *testing.T) {
99
103
}
100
104
` ,
101
105
Check : resource .ComposeTestCheckFunc (
102
- testAccCheckScalewayAccountSSHKeyExists ("scaleway_account_ssh_key.main" ),
106
+ testAccCheckScalewayAccountSSHKeyExists (tt , "scaleway_account_ssh_key.main" ),
103
107
resource .TestCheckResourceAttr ("scaleway_account_ssh_key.main" , "name" , name ),
104
108
resource .TestCheckResourceAttr ("scaleway_account_ssh_key.main" , "public_key" , SSHKey ),
105
109
),
@@ -108,40 +112,42 @@ func TestAccScalewayAccountSSHKey_WithNewLine(t *testing.T) {
108
112
})
109
113
}
110
114
111
- func testAccCheckScalewayAccountSSHKeyDestroy (s * terraform.State ) error {
112
- for _ , rs := range s .RootModule ().Resources {
113
- if rs .Type != "scaleway_account_ssh_key" {
114
- continue
115
- }
115
+ func testAccCheckScalewayAccountSSHKeyDestroy (tt * TestTools ) resource.TestCheckFunc {
116
+ return func (state * terraform.State ) error {
117
+ for _ , rs := range state .RootModule ().Resources {
118
+ if rs .Type != "scaleway_account_ssh_key" {
119
+ continue
120
+ }
116
121
117
- accountAPI := accountAPI (testAccProvider .Meta () )
122
+ accountAPI := accountAPI (tt .Meta )
118
123
119
- _ , err := accountAPI .GetSSHKey (& account.GetSSHKeyRequest {
120
- SSHKeyID : rs .Primary .ID ,
121
- })
124
+ _ , err := accountAPI .GetSSHKey (& account.GetSSHKeyRequest {
125
+ SSHKeyID : rs .Primary .ID ,
126
+ })
122
127
123
- // If no error resource still exist
124
- if err == nil {
125
- return fmt .Errorf ("SSH key (%s) still exists" , rs .Primary .ID )
126
- }
128
+ // If no error resource still exist
129
+ if err == nil {
130
+ return fmt .Errorf ("SSH key (%s) still exists" , rs .Primary .ID )
131
+ }
127
132
128
- // Unexpected api error we return it
129
- if ! is404Error (err ) {
130
- return err
133
+ // Unexpected api error we return it
134
+ if ! is404Error (err ) {
135
+ return err
136
+ }
131
137
}
132
- }
133
138
134
- return nil
139
+ return nil
140
+ }
135
141
}
136
142
137
- func testAccCheckScalewayAccountSSHKeyExists (n string ) resource.TestCheckFunc {
143
+ func testAccCheckScalewayAccountSSHKeyExists (tt * TestTools , n string ) resource.TestCheckFunc {
138
144
return func (s * terraform.State ) error {
139
145
rs , ok := s .RootModule ().Resources [n ]
140
146
if ! ok {
141
147
return fmt .Errorf ("resource not found: %s" , n )
142
148
}
143
149
144
- accountAPI := accountAPI (testAccProvider .Meta () )
150
+ accountAPI := accountAPI (tt .Meta )
145
151
146
152
_ , err := accountAPI .GetSSHKey (& account.GetSSHKeyRequest {
147
153
SSHKeyID : rs .Primary .ID ,
0 commit comments