1
- package gitlab
1
+ package provider
2
2
3
3
import (
4
4
"fmt"
5
+ "strconv"
6
+ "testing"
7
+
5
8
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
6
9
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7
10
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
8
11
"github.com/xanzy/go-gitlab"
9
- "strconv"
10
- "testing"
11
12
)
12
13
13
14
func TestAccGitlabManagedLicense_basic (t * testing.T ) {
14
15
var managedLicense gitlab.ManagedLicense
15
16
rInt := acctest .RandInt ()
16
17
17
18
resource .Test (t , resource.TestCase {
18
- PreCheck : func () {},
19
- Providers : testAccProviders ,
20
- CheckDestroy : testAccCheckManagedLicenseDestroy ,
19
+ PreCheck : func () {},
20
+ ProviderFactories : providerFactories ,
21
+ CheckDestroy : testAccCheckManagedLicenseDestroy ,
21
22
Steps : []resource.TestStep {
22
23
{
23
24
// Create a managed license with an "approved" state
@@ -58,9 +59,7 @@ func testAccCheckGitlabManagedLicenseStatus(n string, license *gitlab.ManagedLic
58
59
return fmt .Errorf ("no project ID is set" )
59
60
}
60
61
61
- conn := testAccProvider .Meta ().(* gitlab.Client )
62
-
63
- licenses , _ , err := conn .ManagedLicenses .ListManagedLicenses (project )
62
+ licenses , _ , err := testGitlabClient .ManagedLicenses .ListManagedLicenses (project )
64
63
if err != nil {
65
64
return err
66
65
}
@@ -76,8 +75,6 @@ func testAccCheckGitlabManagedLicenseStatus(n string, license *gitlab.ManagedLic
76
75
}
77
76
78
77
func testAccCheckManagedLicenseDestroy (state * terraform.State ) error {
79
- conn := testAccProvider .Meta ().(* gitlab.Client )
80
-
81
78
for _ , rs := range state .RootModule ().Resources {
82
79
if rs .Type != "gitlab_managed_licence" {
83
80
continue
@@ -86,7 +83,7 @@ func testAccCheckManagedLicenseDestroy(state *terraform.State) error {
86
83
id , _ := strconv .Atoi (rs .Primary .ID )
87
84
pid := rs .Primary .Attributes ["project" ]
88
85
89
- license , _ , err := conn .ManagedLicenses .GetManagedLicense (pid , id )
86
+ license , _ , err := testGitlabClient .ManagedLicenses .GetManagedLicense (pid , id )
90
87
if err == nil {
91
88
if license != nil && license .ID == id {
92
89
return fmt .Errorf ("license still exists" )
@@ -114,9 +111,7 @@ func testAccCheckGitlabManagedLicenseExists(n string, license *gitlab.ManagedLic
114
111
return fmt .Errorf ("no project ID is set" )
115
112
}
116
113
117
- conn := testAccProvider .Meta ().(* gitlab.Client )
118
-
119
- licenses , _ , err := conn .ManagedLicenses .ListManagedLicenses (project )
114
+ licenses , _ , err := testGitlabClient .ManagedLicenses .ListManagedLicenses (project )
120
115
if err != nil {
121
116
return err
122
117
}
0 commit comments