diff --git a/helper_test.go b/helper_test.go index 028699a84..649b06d41 100644 --- a/helper_test.go +++ b/helper_test.go @@ -1384,7 +1384,7 @@ func createRegistryProvider(t *testing.T, client *Client, org *Organization, reg } } -func createRegistryProviderPlatform(t *testing.T, client *Client, provider *RegistryProvider, version *RegistryProviderVersion) (*RegistryProviderPlatform, func()) { +func createRegistryProviderPlatform(t *testing.T, client *Client, provider *RegistryProvider, version *RegistryProviderVersion, os string, arch string) (*RegistryProviderPlatform, func()) { var providerCleanup func() var versionCleanup func() @@ -1411,12 +1411,20 @@ func createRegistryProviderPlatform(t *testing.T, client *Client, provider *Regi ctx := context.Background() options := RegistryProviderPlatformCreateOptions{ - OS: randomString(t), - Arch: randomString(t), + OS: os, + Arch: arch, Shasum: genSha(t), Filename: randomString(t), } + if os == "" { + options.OS = "linux" + } + + if arch == "" { + options.Arch = "amd64" + } + rpp, err := client.RegistryProviderPlatforms.Create(ctx, versionID, options) if err != nil { diff --git a/registry_provider_platform_integration_test.go b/registry_provider_platform_integration_test.go index 0aa2f6ad9..3f495efd3 100644 --- a/registry_provider_platform_integration_test.go +++ b/registry_provider_platform_integration_test.go @@ -2,7 +2,6 @@ package tfe import ( "context" - "fmt" "testing" "github.com/stretchr/testify/assert" @@ -31,8 +30,8 @@ func TestRegistryProviderPlatformsCreate(t *testing.T) { t.Run("with valid options", func(t *testing.T) { options := RegistryProviderPlatformCreateOptions{ - OS: "foo", - Arch: "scrimbles", + OS: "linux", + Arch: "amd64", Shasum: "shasum", Filename: "filename", } @@ -62,7 +61,7 @@ func TestRegistryProviderPlatformsCreate(t *testing.T) { t.Run("without an OS", func(t *testing.T) { options := RegistryProviderPlatformCreateOptions{ OS: "", - Arch: "scrimbles", + Arch: "amd64", Shasum: "shasum", Filename: "filename", } @@ -89,8 +88,8 @@ func TestRegistryProviderPlatformsCreate(t *testing.T) { t.Run("without a shasum", func(t *testing.T) { options := RegistryProviderPlatformCreateOptions{ - OS: "os", - Arch: "scrimbles", + OS: "linux", + Arch: "amd64", Shasum: "", Filename: "filename", } @@ -103,8 +102,8 @@ func TestRegistryProviderPlatformsCreate(t *testing.T) { t.Run("without a filename", func(t *testing.T) { options := RegistryProviderPlatformCreateOptions{ - OS: "os", - Arch: "scrimbles", + OS: "linux", + Arch: "amd64", Shasum: "shasum", Filename: "", } @@ -117,8 +116,8 @@ func TestRegistryProviderPlatformsCreate(t *testing.T) { t.Run("with a public provider", func(t *testing.T) { options := RegistryProviderPlatformCreateOptions{ - OS: "os", - Arch: "scrimbles", + OS: "linux", + Arch: "amd64", Shasum: "shasum", Filename: "filename", } @@ -140,8 +139,8 @@ func TestRegistryProviderPlatformsCreate(t *testing.T) { t.Run("without a valid registry provider version id", func(t *testing.T) { options := RegistryProviderPlatformCreateOptions{ - OS: "os", - Arch: "scrimbles", + OS: "linux", + Arch: "amd64", Shasum: "shasum", Filename: "filename", } @@ -184,7 +183,7 @@ func TestRegistryProviderPlatformsDelete(t *testing.T) { } t.Run("with a valid version", func(t *testing.T) { - platform, _ := createRegistryProviderPlatform(t, client, provider, version) + platform, _ := createRegistryProviderPlatform(t, client, provider, version, "", "") platformID := RegistryProviderPlatformID{ RegistryProviderVersionID: versionID, @@ -199,8 +198,8 @@ func TestRegistryProviderPlatformsDelete(t *testing.T) { t.Run("with a non-existent version", func(t *testing.T) { platformID := RegistryProviderPlatformID{ RegistryProviderVersionID: versionID, - OS: "nope", - Arch: "no", + OS: "linux", + Arch: "amd64", } err := client.RegistryProviderPlatforms.Delete(ctx, platformID) @@ -230,7 +229,7 @@ func TestRegistryProviderPlatformsRead(t *testing.T) { Version: version.Version, } - platform, platformCleanup := createRegistryProviderPlatform(t, client, provider, version) + platform, platformCleanup := createRegistryProviderPlatform(t, client, provider, version, "", "") defer platformCleanup() t.Run("with valid platform", func(t *testing.T) { @@ -298,10 +297,12 @@ func TestRegistryProviderPlatformsList(t *testing.T) { version, versionCleanup := createRegistryProviderVersion(t, client, provider) defer versionCleanup() - numToCreate := 10 + osl := []string{"linux", "darwin", "windows"} + archl := []string{"amd64", "arm64", "amd64"} + platforms := make([]*RegistryProviderPlatform, 0) - for i := 0; i < numToCreate; i++ { - platform, _ := createRegistryProviderPlatform(t, client, provider, version) + for i, os := range osl { + platform, _ := createRegistryProviderPlatform(t, client, provider, version, os, archl[i]) platforms = append(platforms, platform) } numPlatforms := len(platforms) @@ -317,16 +318,11 @@ func TestRegistryProviderPlatformsList(t *testing.T) { Version: version.Version, } - t.Run("returns all platforms", func(t *testing.T) { - returnedPlatforms, err := client.RegistryProviderPlatforms.List(ctx, versionID, &RegistryProviderPlatformListOptions{ - ListOptions: ListOptions{ - PageNumber: 0, - PageSize: numPlatforms, - }, - }) + t.Run("with no list options", func(t *testing.T) { + returnedPlatforms, err := client.RegistryProviderPlatforms.List(ctx, versionID, nil) require.NoError(t, err) - assert.NotEmpty(t, returnedPlatforms.Items) - assert.Equal(t, numPlatforms, returnedPlatforms.TotalCount) + + require.Len(t, returnedPlatforms.Items, numPlatforms) assert.Equal(t, 1, returnedPlatforms.TotalPages) for _, rp := range returnedPlatforms.Items { foundPlatform := false @@ -340,36 +336,18 @@ func TestRegistryProviderPlatformsList(t *testing.T) { } }) - t.Run("returns pages of platforms", func(t *testing.T) { - numPages := 2 - pageSize := numPlatforms / numPages - - for page := 0; page < numPages; page++ { - testName := fmt.Sprintf("returns page %d of platforms", page) - t.Run(testName, func(t *testing.T) { - returnedPlatforms, err := client.RegistryProviderPlatforms.List(ctx, versionID, &RegistryProviderPlatformListOptions{ - ListOptions: ListOptions{ - PageNumber: page, - PageSize: pageSize, - }, - }) - require.NoError(t, err) - assert.NotEmpty(t, returnedPlatforms.Items) - assert.Equal(t, numPlatforms, returnedPlatforms.TotalCount) - assert.Equal(t, numPages, returnedPlatforms.TotalPages) - assert.Equal(t, pageSize, len(returnedPlatforms.Items)) - for _, rp := range returnedPlatforms.Items { - foundPlatform := false - for _, p := range platforms { - if rp.ID == p.ID { - foundPlatform = true - break - } - } - assert.True(t, foundPlatform, "Expected to find platform %s but did not:\nexpected:\n%v\nreturned\n%v", rp.ID, platforms, returnedPlatforms) - } - }) - } + t.Run("with list options", func(t *testing.T) { + returnedPlatforms, err := client.RegistryProviderPlatforms.List(ctx, versionID, &RegistryProviderPlatformListOptions{ + ListOptions: ListOptions{ + PageNumber: 999, + PageSize: 100, + }, + }) + require.NoError(t, err) + + require.Len(t, returnedPlatforms.Items, 0) + assert.Equal(t, 999, returnedPlatforms.CurrentPage) + assert.Equal(t, numPlatforms, returnedPlatforms.TotalCount) }) })