Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Codelax committed Oct 17, 2024
1 parent 35ccc68 commit a263f31
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
3 changes: 2 additions & 1 deletion api/instance/v1/image_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/scaleway/scaleway-sdk-go/internal/testhelpers"
"github.com/scaleway/scaleway-sdk-go/internal/testhelpers/httprecorder"
"github.com/scaleway/scaleway-sdk-go/scw"
)

func TestWaitForImage(t *testing.T) {
Expand Down Expand Up @@ -36,7 +37,7 @@ func createImage(t *testing.T, instanceAPI *API, imageName string) (*Image, func
t.Helper()
serverRes, err := instanceAPI.CreateServer(&CreateServerRequest{
CommercialType: "DEV1-M",
Image: "ubuntu_focal",
Image: scw.StringPtr("ubuntu_focal"),
})
testhelpers.AssertNoError(t, err)

Expand Down
6 changes: 3 additions & 3 deletions api/instance/v1/instance_sdk_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestServerUpdate(t *testing.T) {
name = "instance_sdk_server_test"
dynamicIPRequired = scw.BoolPtr(true)
commercialType = "START1-S"
image = "f974feac-abae-4365-b988-8ec7d1cec10d"
image = scw.StringPtr("f974feac-abae-4365-b988-8ec7d1cec10d")
enableIPv6 = scw.BoolPtr(true)
bootType = BootTypeLocal
tags = []string{"foo", "bar"}
Expand Down Expand Up @@ -56,7 +56,7 @@ func TestServerUpdate(t *testing.T) {
testhelpers.Equals(t, name, createServerResponse.Server.Name)
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, *image, createServerResponse.Server.Image.ID)
testhelpers.Equals(t, enableIPv6, createServerResponse.Server.EnableIPv6)
testhelpers.Equals(t, bootType, createServerResponse.Server.BootType)
testhelpers.Equals(t, commercialType, createServerResponse.Server.CommercialType)
Expand Down Expand Up @@ -104,7 +104,7 @@ func TestServerUpdate(t *testing.T) {
// Initial values that are not altered in the above request should remaining the same
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, *image, updateServerResponse.Server.Image.ID)
testhelpers.Equals(t, enableIPv6, updateServerResponse.Server.EnableIPv6)
testhelpers.Equals(t, bootType, updateServerResponse.Server.BootType)
testhelpers.Equals(t, commercialType, updateServerResponse.Server.CommercialType)
Expand Down
4 changes: 2 additions & 2 deletions api/instance/v1/instance_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestInstanceHelpers(t *testing.T) {
volumeID string
zone = scw.ZoneFrPar1
project = "ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b"
image = "81b9475d-e1b5-43c2-ac48-4c1a3b640686"
image = scw.StringPtr("81b9475d-e1b5-43c2-ac48-4c1a3b640686")
)

t.Run("create server", func(t *testing.T) {
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestInstanceHelpers_BlockVolume(t *testing.T) {
volumeID2 string
zone = scw.ZoneFrPar1
project = "ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b"
image = "81b9475d-e1b5-43c2-ac48-4c1a3b640686"
image = scw.StringPtr("81b9475d-e1b5-43c2-ac48-4c1a3b640686")
)

t.Run("create server and volume", func(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions api/instance/v1/server_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ const (
// CreateServer creates a server.
func (s *API) CreateServer(req *CreateServerRequest, opts ...scw.RequestOption) (*CreateServerResponse, error) {
// If image is not a UUID we try to fetch it from marketplace.
if req.Image != "" && !validation.IsUUID(req.Image) {
if req.Image != nil && !validation.IsUUID(*req.Image) {
apiMarketplace := marketplace.NewAPI(s.client)
image, err := apiMarketplace.GetLocalImageByLabel(&marketplace.GetLocalImageByLabelRequest{
ImageLabel: req.Image,
ImageLabel: *req.Image,
Zone: req.Zone,
CommercialType: req.CommercialType,
})
if err != nil {
return nil, err
}
req.Image = image.ID
req.Image = scw.StringPtr(image.ID)
}

return s.createServer(req, opts...)
Expand Down
6 changes: 3 additions & 3 deletions api/instance/v1/server_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestAPI_ServerUserData(t *testing.T) {
Zone: scw.ZoneFrPar1,
CommercialType: "DEV1-S",
Name: namegenerator.GetRandomName("srv"),
Image: "f974feac-abae-4365-b988-8ec7d1cec10d",
Image: scw.StringPtr("f974feac-abae-4365-b988-8ec7d1cec10d"),
Project: scw.StringPtr("14d2f7ae-9775-414c-9bed-6810e060d500"),
})
testhelpers.AssertNoError(t, err)
Expand Down Expand Up @@ -86,7 +86,7 @@ func TestAPI_AllServerUserData(t *testing.T) {
Zone: scw.ZoneFrPar1,
CommercialType: "DEV1-S",
Name: namegenerator.GetRandomName("srv"),
Image: "f974feac-abae-4365-b988-8ec7d1cec10d",
Image: scw.StringPtr("f974feac-abae-4365-b988-8ec7d1cec10d"),
Project: scw.StringPtr("14d2f7ae-9775-414c-9bed-6810e060d500"),
})
testhelpers.AssertNoError(t, err)
Expand Down Expand Up @@ -154,7 +154,7 @@ func TestAPI_CreateServer(t *testing.T) {
res, err := instanceAPI.CreateServer(&CreateServerRequest{
Zone: scw.ZoneFrPar1,
CommercialType: "GP1-XS",
Image: "ubuntu_focal",
Image: scw.StringPtr("ubuntu_focal"),
})

testhelpers.AssertNoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion api/instance/v1/snapshot_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func createSnapshot(t *testing.T, instanceAPI *API, snapshotName string) (*Snaps
t.Helper()
serverRes, err := instanceAPI.CreateServer(&CreateServerRequest{
CommercialType: "DEV1-M",
Image: "ubuntu_focal",
Image: scw.StringPtr("ubuntu_focal"),
})
testhelpers.AssertNoError(t, err)

Expand Down

0 comments on commit a263f31

Please sign in to comment.