Skip to content
Merged
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
18 changes: 8 additions & 10 deletions cmd/proxies/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,21 @@ func (p ProxyCmd) Create(ctx context.Context, in ProxyCreateInput) error {
// Build config based on type
switch proxyType {
case kernel.ProxyNewParamsTypeDatacenter:
if in.Country == "" {
return fmt.Errorf("--country is required for datacenter proxy type")
config := kernel.ProxyNewParamsConfigDatacenterProxyConfig{}
if in.Country != "" {
config.Country = kernel.Opt(in.Country)
}
params.Config = kernel.ProxyNewParamsConfigUnion{
OfProxyNewsConfigDatacenterProxyConfig: &kernel.ProxyNewParamsConfigDatacenterProxyConfig{
Country: in.Country,
},
OfProxyNewsConfigDatacenterProxyConfig: &config,
}

case kernel.ProxyNewParamsTypeIsp:
if in.Country == "" {
return fmt.Errorf("--country is required for ISP proxy type")
config := kernel.ProxyNewParamsConfigIspProxyConfig{}
if in.Country != "" {
config.Country = kernel.Opt(in.Country)
}
params.Config = kernel.ProxyNewParamsConfigUnion{
OfProxyNewsConfigIspProxyConfig: &kernel.ProxyNewParamsConfigIspProxyConfig{
Country: in.Country,
},
OfProxyNewsConfigIspProxyConfig: &config,
}

case kernel.ProxyNewParamsTypeResidential:
Expand Down
65 changes: 57 additions & 8 deletions cmd/proxies/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestProxyCreate_Datacenter_Success(t *testing.T) {
// Check config
dcConfig := body.Config.OfProxyNewsConfigDatacenterProxyConfig
assert.NotNil(t, dcConfig)
assert.Equal(t, "US", dcConfig.Country)
assert.Equal(t, "US", dcConfig.Country.Value)

return &kernel.ProxyNewResponse{
ID: "dc-new",
Expand All @@ -48,19 +48,38 @@ func TestProxyCreate_Datacenter_Success(t *testing.T) {
assert.Contains(t, output, "My DC Proxy")
}

func TestProxyCreate_Datacenter_MissingCountry(t *testing.T) {
_ = captureOutput(t)
fake := &FakeProxyService{}
func TestProxyCreate_Datacenter_WithoutCountry(t *testing.T) {
buf := captureOutput(t)

fake := &FakeProxyService{
NewFunc: func(ctx context.Context, body kernel.ProxyNewParams, opts ...option.RequestOption) (*kernel.ProxyNewResponse, error) {
// Verify the request
assert.Equal(t, kernel.ProxyNewParamsTypeDatacenter, body.Type)
assert.Equal(t, "My DC Proxy", body.Name.Value)

// Check config - country should not be set (it should be zero/nil)
dcConfig := body.Config.OfProxyNewsConfigDatacenterProxyConfig
assert.NotNil(t, dcConfig)

return &kernel.ProxyNewResponse{
ID: "dc-new",
Name: "My DC Proxy",
Type: kernel.ProxyNewResponseTypeDatacenter,
}, nil
},
}

p := ProxyCmd{proxies: fake}
err := p.Create(context.Background(), ProxyCreateInput{
Name: "My DC Proxy",
Type: "datacenter",
// Missing required Country
// Country is now optional
})

assert.Error(t, err)
assert.Contains(t, err.Error(), "--country is required for datacenter proxy type")
assert.NoError(t, err)
output := buf.String()
assert.Contains(t, output, "Creating datacenter proxy")
assert.Contains(t, output, "Successfully created proxy")
}

func TestProxyCreate_Residential_Success(t *testing.T) {
Expand Down Expand Up @@ -315,7 +334,7 @@ func TestProxyCreate_ISP_Success(t *testing.T) {
// Verify ISP config
ispConfig := body.Config.OfProxyNewsConfigIspProxyConfig
assert.NotNil(t, ispConfig)
assert.Equal(t, "EU", ispConfig.Country)
assert.Equal(t, "EU", ispConfig.Country.Value)

return &kernel.ProxyNewResponse{
ID: "isp-new",
Expand All @@ -337,3 +356,33 @@ func TestProxyCreate_ISP_Success(t *testing.T) {
assert.Contains(t, output, "Creating isp proxy")
assert.Contains(t, output, "Successfully created proxy")
}

func TestProxyCreate_ISP_WithoutCountry(t *testing.T) {
buf := captureOutput(t)

fake := &FakeProxyService{
NewFunc: func(ctx context.Context, body kernel.ProxyNewParams, opts ...option.RequestOption) (*kernel.ProxyNewResponse, error) {
// Verify ISP config
ispConfig := body.Config.OfProxyNewsConfigIspProxyConfig
assert.NotNil(t, ispConfig)

return &kernel.ProxyNewResponse{
ID: "isp-new",
Name: "ISP Proxy",
Type: kernel.ProxyNewResponseTypeIsp,
}, nil
},
}

p := ProxyCmd{proxies: fake}
err := p.Create(context.Background(), ProxyCreateInput{
Name: "ISP Proxy",
Type: "isp",
// Country is now optional
})

assert.NoError(t, err)
output := buf.String()
assert.Contains(t, output, "Creating isp proxy")
assert.Contains(t, output, "Successfully created proxy")
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/charmbracelet/fang v0.2.0
github.com/golang-jwt/jwt/v5 v5.2.2
github.com/joho/godotenv v1.5.1
github.com/onkernel/kernel-go-sdk v0.15.0
github.com/onkernel/kernel-go-sdk v0.17.0
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
github.com/pterm/pterm v0.12.80
github.com/samber/lo v1.51.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ github.com/muesli/mango-pflag v0.1.0 h1:UADqbYgpUyRoBja3g6LUL+3LErjpsOwaC9ywvBWe
github.com/muesli/mango-pflag v0.1.0/go.mod h1:YEQomTxaCUp8PrbhFh10UfbhbQrM/xJ4i2PB8VTLLW0=
github.com/muesli/roff v0.1.0 h1:YD0lalCotmYuF5HhZliKWlIx7IEhiXeSfq7hNjFqGF8=
github.com/muesli/roff v0.1.0/go.mod h1:pjAHQM9hdUUwm/krAfrLGgJkXJ+YuhtsfZ42kieB2Ig=
github.com/onkernel/kernel-go-sdk v0.15.0 h1:gLeZixS9bhOy1WuEk/eFogHUBjG6UJKN2l+OJNNdE+4=
github.com/onkernel/kernel-go-sdk v0.15.0/go.mod h1:MjUR92i8UPqjrmneyVykae6GuB3GGSmnQtnjf1v74Dc=
github.com/onkernel/kernel-go-sdk v0.17.0 h1:3q7hrfiLTJbUwcJTtPhdnNIXUI4/TUnoklPjUGBoeas=
github.com/onkernel/kernel-go-sdk v0.17.0/go.mod h1:MjUR92i8UPqjrmneyVykae6GuB3GGSmnQtnjf1v74Dc=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down