@@ -5,6 +5,7 @@ package tfe
5
5
6
6
import (
7
7
"context"
8
+ "os"
8
9
"testing"
9
10
"time"
10
11
@@ -139,3 +140,67 @@ func TestPolicySetVersionsUploadURL(t *testing.T) {
139
140
assert .EqualError (t , err , "the Policy Set Version upload URL is empty" )
140
141
})
141
142
}
143
+
144
+ func TestPolicySetVersionsIngressAttributes (t * testing.T ) {
145
+ client := testClient (t )
146
+ ctx := context .Background ()
147
+
148
+ orgTest , orgTestCleanup := createOrganization (t , client )
149
+ t .Cleanup (orgTestCleanup )
150
+
151
+ upgradeOrganizationSubscription (t , client , orgTest )
152
+
153
+ t .Run ("with vcs" , func (t * testing.T ) {
154
+ githubIdentifier := os .Getenv ("GITHUB_POLICY_SET_IDENTIFIER" )
155
+ if githubIdentifier == "" {
156
+ t .Skip ("Export a valid GITHUB_POLICY_SET_IDENTIFIER before running this test" )
157
+ }
158
+
159
+ otTest , otTestCleanup := createOAuthToken (t , client , orgTest )
160
+ t .Cleanup (otTestCleanup )
161
+
162
+ options := PolicySetCreateOptions {
163
+ Name : String ("vcs-policy-set" ),
164
+ Kind : Sentinel ,
165
+ PoliciesPath : String ("policy-sets/foo" ),
166
+ VCSRepo : & VCSRepoOptions {
167
+ Branch : String ("policies" ),
168
+ Identifier : String (githubIdentifier ),
169
+ OAuthTokenID : String (otTest .ID ),
170
+ IngressSubmodules : Bool (true ),
171
+ },
172
+ }
173
+
174
+ ps , err := client .PolicySets .Create (ctx , orgTest .Name , options )
175
+ require .NoError (t , err )
176
+
177
+ ps , err = client .PolicySets .ReadWithOptions (ctx , ps .ID , & PolicySetReadOptions {
178
+ Include : []PolicySetIncludeOpt {
179
+ PolicySetNewestVersion ,
180
+ },
181
+ })
182
+ require .NoError (t , err )
183
+
184
+ psv , err := client .PolicySetVersions .Read (ctx , ps .NewestVersion .ID )
185
+ require .NoError (t , err )
186
+
187
+ require .NotNil (t , psv .IngressAttributes )
188
+ assert .NotZero (t , psv .IngressAttributes .CommitSHA )
189
+ assert .NotZero (t , psv .IngressAttributes .CommitURL )
190
+ assert .NotZero (t , psv .IngressAttributes .Identifier )
191
+ })
192
+
193
+ t .Run ("without vcs" , func (t * testing.T ) {
194
+ psTest , psTestCleanup := createPolicySet (t , client , nil , nil , nil , nil , nil , "" )
195
+ t .Cleanup (psTestCleanup )
196
+
197
+ psv , err := client .PolicySetVersions .Create (ctx , psTest .ID )
198
+ require .NoError (t , err )
199
+
200
+ assert .NotEmpty (t , psv .ID )
201
+ assert .Equal (t , psv .Source , PolicySetVersionSourceAPI )
202
+ assert .Equal (t , psv .PolicySet .ID , psTest .ID )
203
+
204
+ assert .Nil (t , psv .IngressAttributes )
205
+ })
206
+ }
0 commit comments