@@ -21,19 +21,20 @@ func TestAccGitlabManagedLicense_basic(t *testing.T) {
21
21
CheckDestroy : testAccCheckManagedLicenseDestroy ,
22
22
Steps : []resource.TestStep {
23
23
{
24
- // Create a managed license with an "approved " state
24
+ // Create a managed license with an "allowed " state
25
25
SkipFunc : isRunningInCE ,
26
- Config : testManagedLicenseConfig (rInt , "approved " ),
26
+ Config : testManagedLicenseConfig (rInt , "allowed " ),
27
27
Check : resource .ComposeTestCheckFunc (
28
28
testAccCheckGitlabManagedLicenseExists ("gitlab_managed_license.fixme" , & managedLicense ),
29
29
),
30
30
},
31
31
{
32
- // Update the managed license to have a blacklisted state
32
+ // Update the managed license to have a denied state
33
33
SkipFunc : isRunningInCE ,
34
- Config : testManagedLicenseConfig (rInt , "blacklisted " ),
34
+ Config : testManagedLicenseConfig (rInt , "denied " ),
35
35
Check : resource .ComposeTestCheckFunc (
36
- testAccCheckGitlabManagedLicenseStatus ("gitlab_managed_license.fixme" , & managedLicense ),
36
+ //Even though the API accepts "denied", it still returns "blacklisted" until 15.0
37
+ testAccCheckGitlabManagedLicenseStatus ("gitlab_managed_license.fixme" , "blacklisted" , & managedLicense ),
37
38
),
38
39
},
39
40
{
@@ -46,14 +47,79 @@ func TestAccGitlabManagedLicense_basic(t *testing.T) {
46
47
})
47
48
}
48
49
49
- func testAccCheckGitlabManagedLicenseStatus (n string , license * gitlab.ManagedLicense ) resource.TestCheckFunc {
50
+ func TestAccGitlabManagedLicense_deprecatedConfigValues (t * testing.T ) {
51
+ var managedLicense gitlab.ManagedLicense
52
+ rInt := acctest .RandInt ()
53
+
54
+ resource .Test (t , resource.TestCase {
55
+ PreCheck : func () {},
56
+ ProviderFactories : providerFactories ,
57
+ CheckDestroy : testAccCheckManagedLicenseDestroy ,
58
+ Steps : []resource.TestStep {
59
+ {
60
+ // Create a managed license with an "approved" state
61
+ SkipFunc : orSkipFunc (
62
+ isRunningInCE ,
63
+ isGitLabVersionLessThan (testGitlabClient , "15.0" ),
64
+ ),
65
+ Config : testManagedLicenseConfig (rInt , "approved" ),
66
+ Check : resource .ComposeTestCheckFunc (
67
+ testAccCheckGitlabManagedLicenseExists ("gitlab_managed_license.fixme" , & managedLicense ),
68
+ ),
69
+ },
70
+ {
71
+ // Update the managed license to have a blacklisted state
72
+ SkipFunc : orSkipFunc (
73
+ isRunningInCE ,
74
+ isGitLabVersionLessThan (testGitlabClient , "15.0" ),
75
+ ),
76
+ Config : testManagedLicenseConfig (rInt , "blacklisted" ),
77
+ Check : resource .ComposeTestCheckFunc (
78
+ testAccCheckGitlabManagedLicenseStatus ("gitlab_managed_license.fixme" , "blacklisted" , & managedLicense ),
79
+ ),
80
+ },
81
+ {
82
+ SkipFunc : orSkipFunc (
83
+ isRunningInCE ,
84
+ isGitLabVersionLessThan (testGitlabClient , "15.0" ),
85
+ ),
86
+ ResourceName : "gitlab_managed_license.fixme" ,
87
+ ImportState : true ,
88
+ ImportStateVerify : true ,
89
+ },
90
+ },
91
+ })
92
+ }
93
+
94
+ func TestCheckManagedLicenseStatusDiffFunc (t * testing.T ) {
95
+ if ! checkDeprecatedValuesForDiff ("" , "approved" , "allowed" , nil ) {
96
+ t .Log ("approved and allowed should be suppressed" )
97
+ t .Fail ()
98
+ }
99
+
100
+ if ! checkDeprecatedValuesForDiff ("" , "denied" , "blacklisted" , nil ) {
101
+ t .Log ("denied and blacklisted should be suppressed" )
102
+ t .Fail ()
103
+ }
104
+
105
+ if checkDeprecatedValuesForDiff ("" , "denied" , "approved" , nil ) {
106
+ t .Log ("denied and approved should not be suppressed" )
107
+ t .Fail ()
108
+ }
109
+
110
+ if checkDeprecatedValuesForDiff ("" , "allowed" , "blacklisted" , nil ) {
111
+ t .Log ("allowed and blacklisted should not be suppressed" )
112
+ t .Fail ()
113
+ }
114
+ }
115
+
116
+ func testAccCheckGitlabManagedLicenseStatus (resource string , status string , license * gitlab.ManagedLicense ) resource.TestCheckFunc {
50
117
return func (s * terraform.State ) error {
51
- rs , ok := s .RootModule ().Resources [n ]
118
+ rs , ok := s .RootModule ().Resources [resource ]
52
119
if ! ok {
53
- return fmt .Errorf ("not Found: %s" , n )
120
+ return fmt .Errorf ("not Found: %s" , resource )
54
121
}
55
122
56
- licenseStatus := rs .Primary .Attributes ["approval_status" ]
57
123
project := rs .Primary .Attributes ["project" ]
58
124
if project == "" {
59
125
return fmt .Errorf ("no project ID is set" )
@@ -65,7 +131,7 @@ func testAccCheckGitlabManagedLicenseStatus(n string, license *gitlab.ManagedLic
65
131
}
66
132
67
133
for _ , gotLicense := range licenses {
68
- if gotLicense .ApprovalStatus == * stringToApprovalStatus (licenseStatus ) {
134
+ if gotLicense .ApprovalStatus == * stringToApprovalStatus (status ) {
69
135
* license = * gotLicense
70
136
return nil
71
137
}
0 commit comments