Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions internal/testcmd/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
return fmt.Errorf("Account type not found. Ensure you are logged in via the `speakeasy auth login` command or SPEAKEASY_API_KEY environment variable.")
}

if !slices.Contains([]shared.AccountType{shared.AccountTypeEnterprise, shared.AccountTypeBusiness}, *accountType) {
if !IsBusinessTierOrAbove(ctx, *accountType) {
return fmt.Errorf("testing is not supported on the %s account tier. Contact %s for more information", *accountType, styles.RenderSalesEmail())
}

Expand All @@ -64,7 +64,40 @@
}

func CheckTestingAccountType(accountType shared.AccountType) bool {
return slices.Contains([]shared.AccountType{shared.AccountTypeEnterprise, shared.AccountTypeBusiness}, accountType)
return IsBusinessTierOrAboveAccountType(accountType)
}

// IsBusinessTierOrAbove checks if the account type supports business-tier features.
// This includes Business, Enterprise, and OSS account types.
func IsBusinessTierOrAbove(ctx context.Context, accountType shared.AccountType) bool {
// Check standard Business and Enterprise tiers
if slices.Contains([]shared.AccountType{shared.AccountTypeEnterprise, shared.AccountTypeBusiness}, accountType) {
return true
}

Check failure on line 77 in internal/testcmd/testing.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not properly formatted (gofmt)
// Check for OSS account type by comparing string representation
// Since OSS is not in the external SDK enum, we check the string value
if string(accountType) == "OSS" {
return true
}

return false
}

// IsBusinessTierOrAboveAccountType checks if the account type supports business-tier features.
// This is a helper function for cases where we only have the AccountType enum.
func IsBusinessTierOrAboveAccountType(accountType shared.AccountType) bool {
// Check standard Business and Enterprise tiers
if slices.Contains([]shared.AccountType{shared.AccountTypeEnterprise, shared.AccountTypeBusiness}, accountType) {
return true
}

// Check for OSS account type by comparing string representation
if string(accountType) == "OSS" {
return true
}

return false
}

// RebuildTests will prepare the arazzo and gen.lock files for a target ready to rebuild tests.
Expand Down
83 changes: 83 additions & 0 deletions internal/testcmd/testing_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package testcmd

import (
"testing"

"github.com/speakeasy-api/speakeasy-client-sdk-go/v3/pkg/models/shared"
)

func TestIsBusinessTierOrAboveAccountType(t *testing.T) {
tests := []struct {
name string
accountType shared.AccountType
expected bool
}{
{
name: "Business account type should return true",
accountType: shared.AccountTypeBusiness,
expected: true,
},
{
name: "Enterprise account type should return true",
accountType: shared.AccountTypeEnterprise,
expected: true,
},
{
name: "Free account type should return false",
accountType: shared.AccountTypeFree,
expected: false,
},
{
name: "OSS account type should return true",
accountType: shared.AccountType("OSS"),
expected: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := IsBusinessTierOrAboveAccountType(tt.accountType)
if result != tt.expected {
t.Errorf("IsBusinessTierOrAboveAccountType(%v) = %v, expected %v", tt.accountType, result, tt.expected)
}
})
}
}

func TestCheckTestingAccountType(t *testing.T) {
tests := []struct {
name string
accountType shared.AccountType
expected bool
}{
{
name: "Business account type should allow testing",
accountType: shared.AccountTypeBusiness,
expected: true,
},
{
name: "Enterprise account type should allow testing",
accountType: shared.AccountTypeEnterprise,
expected: true,
},
{
name: "Free account type should not allow testing",
accountType: shared.AccountTypeFree,
expected: false,
},
{
name: "OSS account type should allow testing",
accountType: shared.AccountType("OSS"),
expected: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := CheckTestingAccountType(tt.accountType)
if result != tt.expected {
t.Errorf("CheckTestingAccountType(%v) = %v, expected %v", tt.accountType, result, tt.expected)
}
})
}
}

Check failure on line 83 in internal/testcmd/testing_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not properly formatted (gofmt)
Loading