Skip to content

Commit

Permalink
fix serverVolume size checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Codelax committed Jan 21, 2025
1 parent f320569 commit c1a66cc
Show file tree
Hide file tree
Showing 3 changed files with 764 additions and 121 deletions.
14 changes: 3 additions & 11 deletions internal/namespaces/instance/v1/custom_server_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,9 @@ func Test_CreateServer(t *testing.T) {
Cmd: testServerCommand("image=ubuntu_bionic additional-volumes.0=b:1G additional-volumes.1=b:5G additional-volumes.2=b:10G stopped=true"),
Check: core.TestCheckCombine(
core.TestCheckExitCode(0),
func(t *testing.T, ctx *core.CheckFuncCtx) {
t.Helper()
assert.NotNil(t, ctx.Result)
server := testhelpers.Value[*instanceSDK.Server](t, ctx.Result)
size1 := testhelpers.MapTValue(t, server.Volumes, "1").Size
size2 := testhelpers.MapTValue(t, server.Volumes, "2").Size
size3 := testhelpers.MapTValue(t, server.Volumes, "3").Size
assert.Equal(t, 1*scw.GB, instance.SizeValue(size1), "Size of volume should be 1 GB")
assert.Equal(t, 5*scw.GB, instance.SizeValue(size2), "Size of volume should be 5 GB")
assert.Equal(t, 10*scw.GB, instance.SizeValue(size3), "Size of volume should be 10 GB")
},
testServerSBSVolumeSize("1", 1),
testServerSBSVolumeSize("2", 5),
testServerSBSVolumeSize("3", 10),
),
AfterFunc: deleteServerAfterFunc(),
}))
Expand Down
23 changes: 23 additions & 0 deletions internal/namespaces/instance/v1/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ package instance_test
import (
"fmt"
"strings"
"testing"

"github.com/scaleway/scaleway-cli/v2/core"
"github.com/scaleway/scaleway-cli/v2/internal/testhelpers"
block "github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1"
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
"github.com/scaleway/scaleway-sdk-go/scw"
"github.com/stretchr/testify/require"
)

//
Expand Down Expand Up @@ -179,3 +183,22 @@ func createNIC() core.BeforeFunc {
"scw instance private-nic create server-id={{ .Server.ID }} private-network-id={{ .PN.ID }}",
)
}

// testServerSBSVolumeSize checks the size of a volume in Result's server.
// The server must be returned as result of the test's Cmd
func testServerSBSVolumeSize(volumeKey string, sizeInGB int) core.TestCheck {
return func(t *testing.T, ctx *core.CheckFuncCtx) {
t.Helper()
require.NotNil(t, ctx.Result)
server := testhelpers.Value[*instance.Server](t, ctx.Result)
blockAPI := block.NewAPI(ctx.Client)
serverVolume := testhelpers.MapTValue(t, server.Volumes, volumeKey)
volume, err := blockAPI.GetVolume(&block.GetVolumeRequest{
Zone: server.Zone,
VolumeID: serverVolume.ID,
})
require.NoError(t, err)

require.Equal(t, scw.Size(sizeInGB)*scw.GB, volume.Size, "Size of volume should be %d GB", sizeInGB)
}
}
Loading

0 comments on commit c1a66cc

Please sign in to comment.