Skip to content

Commit

Permalink
Fix invalid registry platform os/arch used in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebasslash committed Dec 7, 2022
1 parent 9006329 commit 3316e06
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 61 deletions.
14 changes: 11 additions & 3 deletions helper_test.go
Expand Up @@ -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()

Expand All @@ -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 {
Expand Down
94 changes: 36 additions & 58 deletions registry_provider_platform_integration_test.go
Expand Up @@ -2,7 +2,6 @@ package tfe

import (
"context"
"fmt"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -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",
}
Expand Down Expand Up @@ -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",
}
Expand All @@ -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",
}
Expand All @@ -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: "",
}
Expand All @@ -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",
}
Expand All @@ -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",
}
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
})
})

Expand Down

0 comments on commit 3316e06

Please sign in to comment.