1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
package e2e
import (
"testing"
"github.com/scaleway/scaleway-sdk-go/api/test/v1"
"github.com/scaleway/scaleway-sdk-go/internal/testhelpers"
"github.com/scaleway/scaleway-sdk-go/scw"
)
var defaultOrganizationID = "6170692e-7363-616c-6577-61792e636f6d" // hint: | xxd -ps -r
func newE2EClient(withAuthInClient bool) (*test.API, string, string, error) {
client, err := scw.NewClient(
scw.WithDefaultRegion(scw.RegionFrPar),
scw.WithDefaultOrganizationID(defaultOrganizationID),
scw.WithUserAgent("sdk-e2e-test"),
)
if err != nil {
return nil, "", "", err
}
testClient := test.NewAPI(client)
registerResponse, err := testClient.Register(&test.RegisterRequest{
Username: "sidi",
})
if err != nil {
return nil, "", "", err
}
if withAuthInClient {
client, err = scw.NewClient(
scw.WithDefaultRegion(scw.RegionFrPar),
scw.WithDefaultOrganizationID(defaultOrganizationID),
scw.WithAuth(registerResponse.AccessKey, registerResponse.SecretKey),
scw.WithUserAgent("sdk-e2e-test"),
)
testClient = test.NewAPI(client)
}
return testClient, registerResponse.AccessKey, registerResponse.SecretKey, err
}
func TestAuthInRequest(t *testing.T) {
t.Skip("Skipping test while api-test not yet deployed")
client, accessKey, secretKey, err := newE2EClient(false)
testhelpers.AssertNoError(t, err)
requestWithAuth := scw.WithAuthRequest(accessKey, secretKey)
_, err = client.CreateHuman(&test.CreateHumanRequest{}, requestWithAuth)
testhelpers.AssertNoError(t, err)
}
func TestHuman(t *testing.T) {
t.Skip("Skipping test while api-test not yet deployed")
client, _, _, err := newE2EClient(true)
testhelpers.AssertNoError(t, err)
// create
human, err := client.CreateHuman(&test.CreateHumanRequest{
Height: 170.5,
ShoeSize: 35.1,
AltitudeInMeter: -12,
AltitudeInMillimeter: -12050,
FingersCount: 21,
HairCount: 9223372036854775808,
IsHappy: true,
EyesColor: test.EyeColorsAmber,
OrganizationID: scw.StringPtr("b3ba839a-dcf2-4b0a-ac81-fc32370052a0"),
})
testhelpers.AssertNoError(t, err)
testhelpers.Equals(t, human.Height, 170.5)
testhelpers.Equals(t, human.ShoeSize, float32(35.1))
testhelpers.Equals(t, human.AltitudeInMeter, int32(-12))
testhelpers.Equals(t, human.AltitudeInMillimeter, int64(-12050))
testhelpers.Equals(t, human.FingersCount, uint32(21))
testhelpers.Equals(t, human.HairCount, uint64(9223372036854775808))
testhelpers.Equals(t, human.IsHappy, true)
testhelpers.Equals(t, human.EyesColor, test.EyeColorsAmber)
testhelpers.Equals(t, human.OrganizationID, "b3ba839a-dcf2-4b0a-ac81-fc32370052a0")
// single parameter update
human, err = client.UpdateHuman(&test.UpdateHumanRequest{
HumanID: human.ID,
IsHappy: scw.BoolPtr(false),
})
testhelpers.AssertNoError(t, err)
testhelpers.Equals(t, human.Height, 170.5)
testhelpers.Equals(t, human.ShoeSize, float32(35.1))
testhelpers.Equals(t, human.AltitudeInMeter, int32(-12))
testhelpers.Equals(t, human.AltitudeInMillimeter, int64(-12050))
testhelpers.Equals(t, human.FingersCount, uint32(21))
testhelpers.Equals(t, human.HairCount, uint64(9223372036854775808))
testhelpers.Equals(t, human.IsHappy, false)
testhelpers.Equals(t, human.EyesColor, test.EyeColorsAmber)
testhelpers.Equals(t, human.OrganizationID, "b3ba839a-dcf2-4b0a-ac81-fc32370052a0")
// update
human, err = client.UpdateHuman(&test.UpdateHumanRequest{
HumanID: human.ID,
Height: scw.Float64Ptr(155.666),
ShoeSize: scw.Float32Ptr(36.0),
AltitudeInMeter: scw.Int32Ptr(2147483647),
AltitudeInMillimeter: scw.Int64Ptr(2147483647285),
FingersCount: scw.Uint32Ptr(20),
HairCount: scw.Uint64Ptr(9223372036854775809),
IsHappy: scw.BoolPtr(true),
EyesColor: test.EyeColorsBlue,
})
testhelpers.AssertNoError(t, err)
testhelpers.Equals(t, human.Height, 155.666)
testhelpers.Equals(t, human.ShoeSize, float32(36.0))
testhelpers.Equals(t, human.AltitudeInMeter, int32(2147483647))
testhelpers.Equals(t, human.AltitudeInMillimeter, int64(2147483647285))
testhelpers.Equals(t, human.FingersCount, uint32(20))
testhelpers.Equals(t, human.HairCount, uint64(9223372036854775809))
testhelpers.Equals(t, human.IsHappy, true)
testhelpers.Equals(t, human.EyesColor, test.EyeColorsBlue)
testhelpers.Equals(t, human.OrganizationID, "b3ba839a-dcf2-4b0a-ac81-fc32370052a0")
// get
human, err = client.GetHuman(&test.GetHumanRequest{
HumanID: human.ID,
})
testhelpers.AssertNoError(t, err)
testhelpers.Equals(t, human.Height, 155.666)
testhelpers.Equals(t, human.ShoeSize, float32(36.0))
testhelpers.Equals(t, human.AltitudeInMeter, int32(2147483647))
testhelpers.Equals(t, human.AltitudeInMillimeter, int64(2147483647285))
testhelpers.Equals(t, human.FingersCount, uint32(20))
testhelpers.Equals(t, human.HairCount, uint64(9223372036854775809))
testhelpers.Equals(t, human.IsHappy, true)
testhelpers.Equals(t, human.EyesColor, test.EyeColorsBlue)
testhelpers.Equals(t, human.OrganizationID, "b3ba839a-dcf2-4b0a-ac81-fc32370052a0")
// delete
_, err = client.DeleteHuman(&test.DeleteHumanRequest{
HumanID: human.ID,
})
testhelpers.AssertNoError(t, err)
}
|