@@ -12,6 +12,7 @@ import (
12
12
"regexp"
13
13
"strings"
14
14
"testing"
15
+ "time"
15
16
16
17
retryablehttp "github.com/hashicorp/go-retryablehttp"
17
18
slug "github.com/hashicorp/go-slug"
@@ -1323,6 +1324,60 @@ func TestRegistryModulesRead(t *testing.T) {
1323
1324
})
1324
1325
}
1325
1326
1327
+ func TestRegistryModulesReadRegistry (t * testing.T ) {
1328
+ client := testClient (t )
1329
+ ctx := context .Background ()
1330
+ r := require .New (t )
1331
+
1332
+ // create an org that will be deleted later. the wskp will live here
1333
+ orgTest , orgTestCleanup := createOrganization (t , client )
1334
+ defer orgTestCleanup ()
1335
+
1336
+ org , err := client .Organizations .Read (ctx , orgTest .Name )
1337
+ r .NoError (err )
1338
+ r .NotNil (org )
1339
+
1340
+ githubIdentifier := os .Getenv ("GITHUB_REGISTRY_NO_CODE_MODULE_IDENTIFIER" )
1341
+ if githubIdentifier == "" {
1342
+ t .Skip ("Export a valid GITHUB_REGISTRY_NO_CODE_MODULE_IDENTIFIER before running this test" )
1343
+ }
1344
+
1345
+ token , cleanupToken := createOAuthToken (t , client , org )
1346
+ defer cleanupToken ()
1347
+
1348
+ rmOpts := RegistryModuleCreateWithVCSConnectionOptions {
1349
+ VCSRepo : & RegistryModuleVCSRepoOptions {
1350
+ OrganizationName : String (org .Name ),
1351
+ Identifier : String (githubIdentifier ),
1352
+ Tags : Bool (true ),
1353
+ OAuthTokenID : String (token .ID ),
1354
+ DisplayIdentifier : String (githubIdentifier ),
1355
+ },
1356
+ }
1357
+
1358
+ version := "1.0.0"
1359
+ rm , err := client .RegistryModules .CreateWithVCSConnection (ctx , rmOpts )
1360
+ r .NoError (err )
1361
+
1362
+ // Wait a few seconds to let the module become ready
1363
+ time .Sleep (time .Second * 5 )
1364
+
1365
+ t .Run ("fetch module from registry" , func (t * testing.T ) {
1366
+ rmID := RegistryModuleID {
1367
+ Organization : orgTest .Name ,
1368
+ Name : rm .Name ,
1369
+ Provider : rm .Provider ,
1370
+ Namespace : rm .Namespace ,
1371
+ RegistryName : rm .RegistryName ,
1372
+ }
1373
+ tfm , err := client .RegistryModules .ReadRegistry (ctx , rmID , version )
1374
+ r .NoError (err )
1375
+ r .NotNil (tfm )
1376
+ r .Equal (fmt .Sprintf ("%s/%s/%s/%s" , orgTest .Name , rm .Name , rm .Provider , version ), tfm .ID )
1377
+ r .Equal (version , tfm .Version )
1378
+ })
1379
+ }
1380
+
1326
1381
func TestRegistryModulesDelete (t * testing.T ) {
1327
1382
client := testClient (t )
1328
1383
ctx := context .Background ()
0 commit comments