@@ -1324,40 +1324,81 @@ func TestRegistryModulesRead(t *testing.T) {
1324
1324
})
1325
1325
}
1326
1326
1327
- func TestRegistryModulesReadRegistry (t * testing.T ) {
1327
+ func TestRegistryModulesReadTerraformRegistryModule (t * testing.T ) {
1328
1328
client := testClient (t )
1329
1329
ctx := context .Background ()
1330
1330
r := require .New (t )
1331
1331
1332
- orgTest , orgTestCleanup := createOrganization (t , client )
1333
- defer orgTestCleanup ()
1334
-
1335
1332
githubIdentifier := os .Getenv ("GITHUB_REGISTRY_NO_CODE_MODULE_IDENTIFIER" )
1336
1333
if githubIdentifier == "" {
1337
1334
t .Skip ("Export a valid GITHUB_REGISTRY_NO_CODE_MODULE_IDENTIFIER before running this test" )
1338
1335
}
1339
1336
1340
- token , cleanupToken := createOAuthToken (t , client , orgTest )
1341
- defer cleanupToken ()
1337
+ // NOTE: These test cases use time.Sleep to wait for the module to be ready,
1338
+ // an enhancement to these test cases would be to use a polling mechanism to
1339
+ // check if the module is ready, and then time out if it is not ready after a
1340
+ // certain amount of time.
1342
1341
1343
- rmOpts := RegistryModuleCreateWithVCSConnectionOptions {
1344
- VCSRepo : & RegistryModuleVCSRepoOptions {
1345
- OrganizationName : String (orgTest .Name ),
1346
- Identifier : String (githubIdentifier ),
1347
- Tags : Bool (true ),
1348
- OAuthTokenID : String (token .ID ),
1349
- DisplayIdentifier : String (githubIdentifier ),
1350
- },
1351
- }
1342
+ t .Run ("fetch module from private registry" , func (t * testing.T ) {
1343
+ orgTest , orgTestCleanup := createOrganization (t , client )
1344
+ defer orgTestCleanup ()
1345
+
1346
+ token , cleanupToken := createOAuthToken (t , client , orgTest )
1347
+ defer cleanupToken ()
1348
+
1349
+ rmOpts := RegistryModuleCreateWithVCSConnectionOptions {
1350
+ VCSRepo : & RegistryModuleVCSRepoOptions {
1351
+ OrganizationName : String (orgTest .Name ),
1352
+ Identifier : String (githubIdentifier ),
1353
+ Tags : Bool (true ),
1354
+ OAuthTokenID : String (token .ID ),
1355
+ DisplayIdentifier : String (githubIdentifier ),
1356
+ },
1357
+ }
1358
+
1359
+ version := "1.0.0"
1360
+ rm , err := client .RegistryModules .CreateWithVCSConnection (ctx , rmOpts )
1361
+ r .NoError (err )
1362
+
1363
+ time .Sleep (time .Second * 10 )
1364
+
1365
+ rmID := RegistryModuleID {
1366
+ Organization : orgTest .Name ,
1367
+ Name : rm .Name ,
1368
+ Provider : rm .Provider ,
1369
+ Namespace : rm .Namespace ,
1370
+ RegistryName : rm .RegistryName ,
1371
+ }
1372
+ tfm , err := client .RegistryModules .ReadTerraformRegistryModule (ctx , rmID , version )
1373
+ r .NoError (err )
1374
+ r .NotNil (tfm )
1375
+ r .Equal (fmt .Sprintf ("%s/%s/%s/%s" , orgTest .Name , rm .Name , rm .Provider , version ), tfm .ID )
1376
+ r .Equal (version , tfm .Version )
1377
+ })
1378
+
1379
+ t .Run ("fetch module from public registry" , func (t * testing.T ) {
1380
+ orgTest , orgTestCleanup := createOrganization (t , client )
1381
+ defer orgTestCleanup ()
1382
+
1383
+ token , cleanupToken := createOAuthToken (t , client , orgTest )
1384
+ defer cleanupToken ()
1352
1385
1353
- version := "1.0.0"
1354
- rm , err := client .RegistryModules .CreateWithVCSConnection (ctx , rmOpts )
1355
- r .NoError (err )
1386
+ rmOpts := RegistryModuleCreateWithVCSConnectionOptions {
1387
+ VCSRepo : & RegistryModuleVCSRepoOptions {
1388
+ OrganizationName : String (orgTest .Name ),
1389
+ Identifier : String (githubIdentifier ),
1390
+ Tags : Bool (true ),
1391
+ OAuthTokenID : String (token .ID ),
1392
+ DisplayIdentifier : String (githubIdentifier ),
1393
+ },
1394
+ }
1395
+
1396
+ version := "1.0.0"
1397
+ rm , err := client .RegistryModules .CreateWithVCSConnection (ctx , rmOpts )
1398
+ r .NoError (err )
1356
1399
1357
- // Wait a few seconds to let the module become ready
1358
- time .Sleep (time .Second * 5 )
1400
+ time .Sleep (time .Second * 10 )
1359
1401
1360
- t .Run ("fetch module from registry" , func (t * testing.T ) {
1361
1402
rmID := RegistryModuleID {
1362
1403
Organization : orgTest .Name ,
1363
1404
Name : rm .Name ,
0 commit comments