Skip to content

Commit 6ce1f50

Browse files
test: Add integration test.
This tests reading a module from the registry.
1 parent 8f7c17a commit 6ce1f50

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

registry_module_integration_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"regexp"
1313
"strings"
1414
"testing"
15+
"time"
1516

1617
retryablehttp "github.com/hashicorp/go-retryablehttp"
1718
slug "github.com/hashicorp/go-slug"
@@ -1323,6 +1324,60 @@ func TestRegistryModulesRead(t *testing.T) {
13231324
})
13241325
}
13251326

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+
13261381
func TestRegistryModulesDelete(t *testing.T) {
13271382
client := testClient(t)
13281383
ctx := context.Background()

0 commit comments

Comments
 (0)