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
186 changes: 161 additions & 25 deletions api/instance/v1/instance_sdk.go

Large diffs are not rendered by default.

32 changes: 28 additions & 4 deletions api/instance/v1/instance_sdk_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,21 @@ func TestServerUpdate(t *testing.T) {
enableIPv6 = true
bootType = BootTypeLocal
tags = []string{"foo", "bar"}
organization = "d429f6a1-c0a6-48cf-8b5a-1f9dfe76ffd3"
project = "14d2f7ae-9775-414c-9bed-6810e060d500"
)

t.Run("create server", func(t *testing.T) {
// Create server
createServerResponse, err := instanceAPI.CreateServer(&CreateServerRequest{
Zone: zone,
Name: name,
Organization: organization,
Project: &project,
Image: image,
EnableIPv6: enableIPv6,
CommercialType: commercialType,
Tags: tags,
DynamicIPRequired: dynamicIPRequired,
BootType: &bootType,
})
testhelpers.AssertNoError(t, err)
serverID = createServerResponse.Server.ID
Expand All @@ -53,7 +54,8 @@ func TestServerUpdate(t *testing.T) {
}

testhelpers.Equals(t, name, createServerResponse.Server.Name)
testhelpers.Equals(t, organization, createServerResponse.Server.Organization)
testhelpers.Equals(t, project, createServerResponse.Server.Project)
testhelpers.Equals(t, project, createServerResponse.Server.Organization)
testhelpers.Equals(t, image, createServerResponse.Server.Image.ID)
testhelpers.Equals(t, enableIPv6, createServerResponse.Server.EnableIPv6)
testhelpers.Equals(t, bootType, createServerResponse.Server.BootType)
Expand All @@ -62,6 +64,27 @@ func TestServerUpdate(t *testing.T) {
testhelpers.Equals(t, *dynamicIPRequired, createServerResponse.Server.DynamicIPRequired)
})

t.Run("create server with orga (deprecated)", func(t *testing.T) {
// Create server
createServerResponse, err := instanceAPI.CreateServer(&CreateServerRequest{
Zone: zone,
Name: name,
Organization: &project,
Image: image,
})
testhelpers.AssertNoError(t, err)

testhelpers.Equals(t, project, createServerResponse.Server.Project)
testhelpers.Equals(t, project, createServerResponse.Server.Organization)

// Delete Server
err = instanceAPI.DeleteServer(&DeleteServerRequest{
Zone: zone,
ServerID: createServerResponse.Server.ID,
})
testhelpers.AssertNoError(t, err)
})

t.Run("update server", func(t *testing.T) {
var (
newName = "some_new_name_for_server"
Expand All @@ -79,7 +102,8 @@ func TestServerUpdate(t *testing.T) {
testhelpers.AssertNoError(t, err)

// Initial values that are not altered in the above request should remaining the same
testhelpers.Equals(t, organization, updateServerResponse.Server.Organization)
testhelpers.Equals(t, project, updateServerResponse.Server.Project)
testhelpers.Equals(t, project, updateServerResponse.Server.Organization)
testhelpers.Equals(t, image, updateServerResponse.Server.Image.ID)
testhelpers.Equals(t, enableIPv6, updateServerResponse.Server.EnableIPv6)
testhelpers.Equals(t, bootType, updateServerResponse.Server.BootType)
Expand Down
28 changes: 14 additions & 14 deletions api/instance/v1/instance_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ func TestInstanceHelpers(t *testing.T) {
instanceAPI := NewAPI(client)

var (
serverID string
ipID string
volumeID string
zone = scw.ZoneFrPar1
organization = "d429f6a1-c0a6-48cf-8b5a-1f9dfe76ffd3"
image = "f974feac-abae-4365-b988-8ec7d1cec10d"
reverse = &NullableStringValue{Value: "1.1.1.1"}
nullReverse = &NullableStringValue{Null: true}
serverID string
ipID string
volumeID string
zone = scw.ZoneFrPar1
project = "d429f6a1-c0a6-48cf-8b5a-1f9dfe76ffd3"
image = "f974feac-abae-4365-b988-8ec7d1cec10d"
reverse = &NullableStringValue{Value: "1.1.1.1"}
nullReverse = &NullableStringValue{Null: true}
)

t.Run("create server", func(t *testing.T) {
createServerResponse, err := instanceAPI.CreateServer(&CreateServerRequest{
Zone: zone,
Name: "instance_utils_test",
Organization: organization,
Image: image,
Zone: zone,
Name: "instance_utils_test",
Project: &project,
Image: image,
})
testhelpers.AssertNoError(t, err)
serverID = createServerResponse.Server.ID
Expand All @@ -45,8 +45,8 @@ func TestInstanceHelpers(t *testing.T) {
t.Run("test ip related functions", func(t *testing.T) {
// Create IP
createIPResponse, err := instanceAPI.CreateIP(&CreateIPRequest{
Zone: zone,
Organization: &organization,
Zone: zone,
Project: &project,
})
testhelpers.AssertNoError(t, err)
ipID = createIPResponse.IP.ID
Expand Down
6 changes: 6 additions & 0 deletions api/instance/v1/security_group_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type UpdateSecurityGroupRequest struct {
OutboundDefaultPolicy *SecurityGroupPolicy `json:"outbound_default_policy,omitempty"`
Stateful *bool `json:"stateful,omitempty"`
OrganizationDefault *bool `json:"organization_default,omitempty"`
ProjectDefault *bool `json:"project_default,omitempty"`
}

type UpdateSecurityGroupResponse struct {
Expand Down Expand Up @@ -54,7 +55,9 @@ func (s *API) UpdateSecurityGroup(req *UpdateSecurityGroupRequest, opts ...scw.R
Name: getSGResponse.SecurityGroup.Name,
Description: getSGResponse.SecurityGroup.Description,
Organization: getSGResponse.SecurityGroup.Organization,
Project: getSGResponse.SecurityGroup.Project,
OrganizationDefault: getSGResponse.SecurityGroup.OrganizationDefault,
ProjectDefault: getSGResponse.SecurityGroup.ProjectDefault,
OutboundDefaultPolicy: getSGResponse.SecurityGroup.OutboundDefaultPolicy,
InboundDefaultPolicy: getSGResponse.SecurityGroup.InboundDefaultPolicy,
Stateful: getSGResponse.SecurityGroup.Stateful,
Expand Down Expand Up @@ -84,6 +87,9 @@ func (s *API) UpdateSecurityGroup(req *UpdateSecurityGroupRequest, opts ...scw.R
if req.OrganizationDefault != nil {
setRequest.OrganizationDefault = *req.OrganizationDefault
}
if req.ProjectDefault != nil {
setRequest.ProjectDefault = *req.ProjectDefault
}

setRes, err := s.setSecurityGroup(setRequest, opts...)
if err != nil {
Expand Down
15 changes: 8 additions & 7 deletions api/instance/v1/security_group_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ func TestAPI_UpdateSecurityGroup(t *testing.T) {
instanceAPI := NewAPI(client)

var (
zone = scw.ZoneFrPar1
organization = "b3ba839a-dcf2-4b0a-ac81-fc32370052a0"
zone = scw.ZoneFrPar1
project = "b3ba839a-dcf2-4b0a-ac81-fc32370052a0"
)

createResponse, err := instanceAPI.CreateSecurityGroup(&CreateSecurityGroupRequest{
Expand All @@ -30,7 +30,7 @@ func TestAPI_UpdateSecurityGroup(t *testing.T) {
Stateful: true,
InboundDefaultPolicy: SecurityGroupPolicyAccept,
OutboundDefaultPolicy: SecurityGroupPolicyDrop,
Organization: organization,
Project: &project,
})

testhelpers.AssertNoError(t, err)
Expand All @@ -47,7 +47,7 @@ func TestAPI_UpdateSecurityGroup(t *testing.T) {
InboundDefaultPolicy: &drop,
OutboundDefaultPolicy: &accept,
// Keep false here, switch it to true is too dangerous for the one who update the test cassette.
OrganizationDefault: scw.BoolPtr(false),
ProjectDefault: scw.BoolPtr(false),
})

testhelpers.AssertNoError(t, err)
Expand All @@ -56,6 +56,7 @@ func TestAPI_UpdateSecurityGroup(t *testing.T) {
testhelpers.Equals(t, SecurityGroupPolicyDrop, updateResponse.SecurityGroup.InboundDefaultPolicy)
testhelpers.Equals(t, SecurityGroupPolicyAccept, updateResponse.SecurityGroup.OutboundDefaultPolicy)
testhelpers.Equals(t, false, updateResponse.SecurityGroup.Stateful)
testhelpers.Equals(t, false, updateResponse.SecurityGroup.ProjectDefault)
testhelpers.Equals(t, false, updateResponse.SecurityGroup.OrganizationDefault)

err = instanceAPI.DeleteSecurityGroup(&DeleteSecurityGroupRequest{
Expand All @@ -75,8 +76,8 @@ func TestAPI_UpdateSecurityGroupRule(t *testing.T) {
instanceAPI := NewAPI(client)

var (
zone = scw.ZoneFrPar1
organization = "b3ba839a-dcf2-4b0a-ac81-fc32370052a0"
zone = scw.ZoneFrPar1
project = "b3ba839a-dcf2-4b0a-ac81-fc32370052a0"
)

bootstrap := func(t *testing.T) (*SecurityGroup, *SecurityGroupRule, func()) {
Expand All @@ -87,7 +88,7 @@ func TestAPI_UpdateSecurityGroupRule(t *testing.T) {
Stateful: true,
InboundDefaultPolicy: SecurityGroupPolicyAccept,
OutboundDefaultPolicy: SecurityGroupPolicyDrop,
Organization: organization,
Project: &project,
})

testhelpers.AssertNoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions api/instance/v1/server_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestAPI_ServerUserData(t *testing.T) {
CommercialType: "DEV1-S",
Name: namegenerator.GetRandomName("srv"),
Image: "f974feac-abae-4365-b988-8ec7d1cec10d",
Organization: "14d2f7ae-9775-414c-9bed-6810e060d500",
Project: scw.StringPtr("14d2f7ae-9775-414c-9bed-6810e060d500"),
})
testhelpers.AssertNoError(t, err)

Expand Down Expand Up @@ -88,7 +88,7 @@ func TestAPI_AllServerUserData(t *testing.T) {
CommercialType: "DEV1-S",
Name: namegenerator.GetRandomName("srv"),
Image: "f974feac-abae-4365-b988-8ec7d1cec10d",
Organization: "14d2f7ae-9775-414c-9bed-6810e060d500",
Project: scw.StringPtr("14d2f7ae-9775-414c-9bed-6810e060d500"),
})
testhelpers.AssertNoError(t, err)

Expand Down
Loading