From eb48674aab3e2e6a55809de899f77ff2e0674d56 Mon Sep 17 00:00:00 2001 From: Sagar Batchu Date: Thu, 17 Jul 2025 16:40:10 -0700 Subject: [PATCH] feat: Add OSS license type with Business tier privileges MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add support for OSS (Open Source Software) license type that has the same feature access as Business tier accounts. This enables OSS projects to access premium features like SDK testing. Changes: - Add IsBusinessTierOrAbove() helper functions that recognize OSS accounts - Update CheckTestingEnabled() to use new helper for account type validation - OSS accounts now have same testing privileges as Business/Enterprise tiers - Add comprehensive tests to verify OSS account type functionality 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- internal/testcmd/testing.go | 37 +++++++++++++- internal/testcmd/testing_test.go | 83 ++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 internal/testcmd/testing_test.go diff --git a/internal/testcmd/testing.go b/internal/testcmd/testing.go index 9317e2a1..986ff7d0 100644 --- a/internal/testcmd/testing.go +++ b/internal/testcmd/testing.go @@ -52,7 +52,7 @@ func CheckTestingEnabled(ctx context.Context) error { 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()) } @@ -64,7 +64,40 @@ func CheckTestingEnabled(ctx context.Context) error { } 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 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. diff --git a/internal/testcmd/testing_test.go b/internal/testcmd/testing_test.go new file mode 100644 index 00000000..36812c75 --- /dev/null +++ b/internal/testcmd/testing_test.go @@ -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) + } + }) + } +} \ No newline at end of file