@@ -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,126 @@ func TestRegistryModulesRead(t *testing.T) {
1323
1324
})
1324
1325
}
1325
1326
1327
+ func TestRegistryModulesReadTerraformRegistryModule (t * testing.T ) {
1328
+ client := testClient (t )
1329
+ ctx := context .Background ()
1330
+ r := require .New (t )
1331
+
1332
+ githubIdentifier := os .Getenv ("GITHUB_REGISTRY_NO_CODE_MODULE_IDENTIFIER" )
1333
+ if githubIdentifier == "" {
1334
+ t .Skip ("Export a valid GITHUB_REGISTRY_NO_CODE_MODULE_IDENTIFIER before running this test" )
1335
+ }
1336
+
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.
1341
+
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 (rm .Name , tfm .Name )
1377
+ r .Equal ("A test Terraform module for use in CI pipelines" , tfm .Description )
1378
+ r .Equal (rm .Provider , tfm .Provider )
1379
+ r .Equal (rm .Namespace , tfm .Namespace )
1380
+ r .Equal (version , tfm .Version )
1381
+ r .Equal ("" , tfm .Tag )
1382
+ r .Equal (0 , tfm .Downloads )
1383
+ r .False (tfm .Verified )
1384
+ r .NotNil (tfm .Root )
1385
+ r .Equal (rm .Name , tfm .Root .Name )
1386
+ r .Equal ("" , tfm .Root .Readme )
1387
+ r .False (tfm .Root .Empty )
1388
+ r .Len (tfm .Root .Inputs , 1 )
1389
+ r .Len (tfm .Root .Outputs , 1 )
1390
+ r .Len (tfm .Root .ProviderDependencies , 1 )
1391
+ r .Len (tfm .Root .Resources , 1 )
1392
+ })
1393
+
1394
+ t .Run ("fetch module from public registry" , func (t * testing.T ) {
1395
+ orgTest , orgTestCleanup := createOrganization (t , client )
1396
+ defer orgTestCleanup ()
1397
+
1398
+ token , cleanupToken := createOAuthToken (t , client , orgTest )
1399
+ defer cleanupToken ()
1400
+
1401
+ rmOpts := RegistryModuleCreateWithVCSConnectionOptions {
1402
+ VCSRepo : & RegistryModuleVCSRepoOptions {
1403
+ OrganizationName : String (orgTest .Name ),
1404
+ Identifier : String (githubIdentifier ),
1405
+ Tags : Bool (true ),
1406
+ OAuthTokenID : String (token .ID ),
1407
+ DisplayIdentifier : String (githubIdentifier ),
1408
+ },
1409
+ }
1410
+
1411
+ version := "1.0.0"
1412
+ rm , err := client .RegistryModules .CreateWithVCSConnection (ctx , rmOpts )
1413
+ r .NoError (err )
1414
+
1415
+ time .Sleep (time .Second * 10 )
1416
+
1417
+ rmID := RegistryModuleID {
1418
+ Organization : orgTest .Name ,
1419
+ Name : rm .Name ,
1420
+ Provider : rm .Provider ,
1421
+ Namespace : rm .Namespace ,
1422
+ RegistryName : rm .RegistryName ,
1423
+ }
1424
+ tfm , err := client .RegistryModules .ReadTerraformRegistryModule (ctx , rmID , version )
1425
+ r .NoError (err )
1426
+ r .NotNil (tfm )
1427
+ r .Equal (fmt .Sprintf ("%s/%s/%s/%s" , orgTest .Name , rm .Name , rm .Provider , version ), tfm .ID )
1428
+ r .Equal (rm .Name , tfm .Name )
1429
+ r .Equal ("A test Terraform module for use in CI pipelines" , tfm .Description )
1430
+ r .Equal (rm .Provider , tfm .Provider )
1431
+ r .Equal (rm .Namespace , tfm .Namespace )
1432
+ r .Equal (version , tfm .Version )
1433
+ r .Equal ("" , tfm .Tag )
1434
+ r .Equal (0 , tfm .Downloads )
1435
+ r .False (tfm .Verified )
1436
+ r .NotNil (tfm .Root )
1437
+ r .Equal (rm .Name , tfm .Root .Name )
1438
+ r .Equal ("" , tfm .Root .Readme )
1439
+ r .False (tfm .Root .Empty )
1440
+ r .Len (tfm .Root .Inputs , 1 )
1441
+ r .Len (tfm .Root .Outputs , 1 )
1442
+ r .Len (tfm .Root .ProviderDependencies , 1 )
1443
+ r .Len (tfm .Root .Resources , 1 )
1444
+ })
1445
+ }
1446
+
1326
1447
func TestRegistryModulesDelete (t * testing.T ) {
1327
1448
client := testClient (t )
1328
1449
ctx := context .Background ()
0 commit comments