Skip to content

Commit 8bf0ad0

Browse files
jremy42remyleone
andauthored
tests(rdb): update engine (scaleway#4404)
Co-authored-by: Rémy Léone <[email protected]>
1 parent 0472957 commit 8bf0ad0

File tree

100 files changed

+96653
-29517
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+96653
-29517
lines changed

internal/namespaces/rdb/v1/custom_acl_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
func Test_AddACL(t *testing.T) {
1212
t.Run("Simple", core.Test(&core.TestConfig{
1313
Commands: rdb.GetCommands(),
14-
BeforeFunc: createInstance("PostgreSQL-12"),
14+
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
1515
Cmd: "scw rdb acl add 1.2.3.4 instance-id={{ .Instance.ID }} --wait",
1616
Check: core.TestCheckCombine(
1717
core.TestCheckGolden(),
@@ -25,7 +25,7 @@ func Test_AddACL(t *testing.T) {
2525

2626
t.Run("Simple with description", core.Test(&core.TestConfig{
2727
Commands: rdb.GetCommands(),
28-
BeforeFunc: createInstance("PostgreSQL-12"),
28+
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
2929
Cmd: "scw rdb acl add 1.2.3.4 instance-id={{ .Instance.ID }} description=some-unique-description --wait",
3030
Check: core.TestCheckCombine(
3131
core.TestCheckGolden(),
@@ -39,7 +39,7 @@ func Test_AddACL(t *testing.T) {
3939

4040
t.Run("Multiple", core.Test(&core.TestConfig{
4141
Commands: rdb.GetCommands(),
42-
BeforeFunc: createInstance("PostgreSQL-12"),
42+
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
4343
Cmd: "scw rdb acl add 1.2.3.4 192.168.1.0/30 10.10.10.10 instance-id={{ .Instance.ID }} --wait",
4444
Check: core.TestCheckCombine(
4545
core.TestCheckGolden(),
@@ -53,7 +53,7 @@ func Test_AddACL(t *testing.T) {
5353

5454
t.Run("Multiple with description", core.Test(&core.TestConfig{
5555
Commands: rdb.GetCommands(),
56-
BeforeFunc: createInstance("PostgreSQL-12"),
56+
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
5757
Cmd: "scw rdb acl add 1.2.3.4 192.168.1.0/30 10.10.10.10 instance-id={{ .Instance.ID }} description=some-unique-description --wait",
5858
Check: core.TestCheckCombine(
5959
core.TestCheckGolden(),
@@ -69,7 +69,7 @@ func Test_AddACL(t *testing.T) {
6969
func Test_DeleteACL(t *testing.T) {
7070
t.Run("Simple", core.Test(&core.TestConfig{
7171
Commands: rdb.GetCommands(),
72-
BeforeFunc: createInstance("PostgreSQL-12"),
72+
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
7373
Cmd: "scw rdb acl delete 0.0.0.0/0 instance-id={{ .Instance.ID }} --wait",
7474
Check: core.TestCheckCombine(
7575
core.TestCheckGolden(),
@@ -84,7 +84,7 @@ func Test_DeleteACL(t *testing.T) {
8484
t.Run("Multiple when set", core.Test(&core.TestConfig{
8585
Commands: rdb.GetCommands(),
8686
BeforeFunc: core.BeforeFuncCombine(
87-
createInstance("PostgreSQL-12"),
87+
fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}"),
8888
core.ExecBeforeCmd("scw rdb acl add 1.2.3.4 192.168.1.0/32 10.10.10.10 instance-id={{ .Instance.ID }} --wait"),
8989
),
9090
Cmd: "scw rdb acl delete 1.2.3.4/32 192.168.1.0/32 10.10.10.10/32 instance-id={{ .Instance.ID }} --wait",
@@ -101,7 +101,7 @@ func Test_DeleteACL(t *testing.T) {
101101
t.Run("Multiple when not set", core.Test(&core.TestConfig{
102102
Commands: rdb.GetCommands(),
103103
BeforeFunc: core.BeforeFuncCombine(
104-
createInstance("PostgreSQL-12"),
104+
fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}"),
105105
core.ExecBeforeCmd("scw rdb acl add 192.168.1.0/32 instance-id={{ .Instance.ID }} --wait"),
106106
),
107107
Cmd: "scw rdb acl delete 1.2.3.4/32 192.168.1.0/32 10.10.10.10/32 instance-id={{ .Instance.ID }} --wait",
@@ -119,7 +119,7 @@ func Test_DeleteACL(t *testing.T) {
119119
func Test_SetACL(t *testing.T) {
120120
t.Run("Simple", core.Test(&core.TestConfig{
121121
Commands: rdb.GetCommands(),
122-
BeforeFunc: createInstance("PostgreSQL-12"),
122+
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
123123
Cmd: "scw rdb acl set 1.2.3.4 instance-id={{ .Instance.ID }} descriptions.0=something --wait",
124124
Check: core.TestCheckCombine(
125125
core.TestCheckGolden(),
@@ -136,7 +136,7 @@ func Test_SetACL(t *testing.T) {
136136
t.Run("Multiple", core.Test(&core.TestConfig{
137137
Commands: rdb.GetCommands(),
138138
BeforeFunc: core.BeforeFuncCombine(
139-
createInstance("PostgreSQL-12"),
139+
fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}"),
140140
core.ExecBeforeCmd("scw rdb acl add 1.2.3.4 192.168.1.0/32 10.10.10.10 instance-id={{ .Instance.ID }} --wait"),
141141
),
142142
Cmd: "scw rdb acl set 1.2.3.4 192.168.1.0/31 11.11.11.11 instance-id={{ .Instance.ID }} descriptions.0=first descriptions.1=second descriptions.2=third --wait",

internal/namespaces/rdb/v1/custom_endpoint_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func Test_EndpointCreate(t *testing.T) {
3737
Commands: cmds,
3838
BeforeFunc: core.BeforeFuncCombine(
3939
createPN(),
40-
createInstance("PostgreSQL-15"),
40+
fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}"),
4141
),
4242
Cmd: "scw rdb endpoint create {{ .Instance.ID }} private-network.private-network-id={{ .PN.ID }} private-network.service-ip={{ .IPNet }} --wait",
4343
Check: core.TestCheckCombine(
@@ -58,7 +58,7 @@ func Test_EndpointCreate(t *testing.T) {
5858
Commands: cmds,
5959
BeforeFunc: core.BeforeFuncCombine(
6060
createPN(),
61-
createInstance("PostgreSQL-15"),
61+
fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}"),
6262
),
6363
Cmd: "scw rdb endpoint create {{ .Instance.ID }} private-network.private-network-id={{ .PN.ID }} private-network.enable-ipam=true --wait",
6464
Check: core.TestCheckCombine(
@@ -127,7 +127,7 @@ func Test_EndpointDelete(t *testing.T) {
127127
t.Run("All", core.Test(&core.TestConfig{
128128
Commands: cmds,
129129
BeforeFunc: core.BeforeFuncCombine(
130-
createInstance("PostgreSQL-15"),
130+
fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}"),
131131
listEndpointsInMeta(),
132132
),
133133
Cmd: "scw rdb endpoint delete {{ .PublicEndpoint.ID }} instance-id={{ .Instance.ID }} --wait",

internal/namespaces/rdb/v1/custom_instance_test.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const (
2525
func Test_ListInstance(t *testing.T) {
2626
t.Run("Simple", core.Test(&core.TestConfig{
2727
Commands: rdb.GetCommands(),
28-
BeforeFunc: createInstance("PostgreSQL-12"),
28+
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
2929
Cmd: "scw rdb instance list",
3030
Check: core.TestCheckGolden(),
3131
AfterFunc: deleteInstance(),
@@ -35,7 +35,7 @@ func Test_ListInstance(t *testing.T) {
3535
func Test_CloneInstance(t *testing.T) {
3636
t.Run("Simple", core.Test(&core.TestConfig{
3737
Commands: rdb.GetCommands(),
38-
BeforeFunc: createInstance("PostgreSQL-12"),
38+
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
3939
Cmd: "scw rdb instance clone {{ .Instance.ID }} node-type=DB-DEV-M name=foobar --wait",
4040
Check: core.TestCheckGolden(),
4141
AfterFunc: deleteInstance(),
@@ -153,7 +153,7 @@ func Test_CreateInstanceInitEndpoints(t *testing.T) {
153153
func Test_GetInstance(t *testing.T) {
154154
t.Run("Simple", core.Test(&core.TestConfig{
155155
Commands: rdb.GetCommands(),
156-
BeforeFunc: createInstance("PostgreSQL-12"),
156+
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
157157
Cmd: "scw rdb instance get {{ .Instance.ID }}",
158158
Check: core.TestCheckGolden(),
159159
AfterFunc: deleteInstance(),
@@ -163,7 +163,7 @@ func Test_GetInstance(t *testing.T) {
163163
func Test_UpgradeInstance(t *testing.T) {
164164
t.Run("Simple", core.Test(&core.TestConfig{
165165
Commands: rdb.GetCommands(),
166-
BeforeFunc: createInstance("PostgreSQL-12"),
166+
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
167167
Cmd: "scw rdb instance upgrade {{ .Instance.ID }} node-type=DB-DEV-M --wait",
168168
Check: core.TestCheckGolden(),
169169
AfterFunc: deleteInstance(),
@@ -173,7 +173,7 @@ func Test_UpgradeInstance(t *testing.T) {
173173
func Test_UpdateInstance(t *testing.T) {
174174
t.Run("Update instance name", core.Test(&core.TestConfig{
175175
Commands: rdb.GetCommands(),
176-
BeforeFunc: createInstance("PostgreSQL-12"),
176+
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
177177
Cmd: "scw rdb instance update {{ .Instance.ID }} name=foo --wait",
178178
Check: core.TestCheckCombine(
179179
func(t *testing.T, ctx *core.CheckFuncCtx) {
@@ -188,7 +188,7 @@ func Test_UpdateInstance(t *testing.T) {
188188

189189
t.Run("Update instance tags", core.Test(&core.TestConfig{
190190
Commands: rdb.GetCommands(),
191-
BeforeFunc: createInstance("PostgreSQL-12"),
191+
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
192192
Cmd: "scw rdb instance update {{ .Instance.ID }} tags.0=a --wait",
193193
Check: core.TestCheckCombine(
194194
func(t *testing.T, ctx *core.CheckFuncCtx) {
@@ -203,7 +203,7 @@ func Test_UpdateInstance(t *testing.T) {
203203

204204
t.Run("Set a timezone", core.Test(&core.TestConfig{
205205
Commands: rdb.GetCommands(),
206-
BeforeFunc: createInstance("PostgreSQL-12"),
206+
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
207207
Cmd: "scw rdb instance update {{ .Instance.ID }} settings.0.name=timezone settings.0.value=UTC --wait",
208208
Check: core.TestCheckCombine(
209209
func(t *testing.T, ctx *core.CheckFuncCtx) {
@@ -219,7 +219,7 @@ func Test_UpdateInstance(t *testing.T) {
219219

220220
t.Run("Modify default work_mem from 4 to 8 MB", core.Test(&core.TestConfig{
221221
Commands: rdb.GetCommands(),
222-
BeforeFunc: createInstance("PostgreSQL-12"),
222+
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
223223
Cmd: "scw rdb instance update {{ .Instance.ID }} settings.0.name=work_mem settings.0.value=8 --wait",
224224
Check: core.TestCheckCombine(
225225
func(t *testing.T, ctx *core.CheckFuncCtx) {
@@ -236,7 +236,8 @@ func Test_UpdateInstance(t *testing.T) {
236236
t.Run("Modify 3 settings + add a new one", core.Test(&core.TestConfig{
237237
Commands: rdb.GetCommands(),
238238
BeforeFunc: core.BeforeFuncCombine(
239-
createInstance("PostgreSQL-12"),
239+
fetchLatestEngine("PostgreSQL"),
240+
createInstance("{{.latestEngine}}"),
240241
core.ExecBeforeCmd("scw rdb instance update {{ .Instance.ID }} settings.0.name=work_mem settings.0.value=8"+
241242
" settings.1.name=max_connections settings.1.value=200"+
242243
" settings.2.name=effective_cache_size settings.2.value=1000"+
@@ -272,7 +273,8 @@ func Test_Connect(t *testing.T) {
272273
Commands: rdb.GetCommands(),
273274
BeforeFunc: core.BeforeFuncCombine(
274275
core.BeforeFuncStoreInMeta("username", user),
275-
createInstance("MySQL-8"),
276+
fetchLatestEngine("MySQL"),
277+
createInstance("{{.latestEngine}}"),
276278
),
277279
Cmd: "scw rdb instance connect {{ .Instance.ID }} username={{ .username }}",
278280
Check: core.TestCheckCombine(
@@ -287,8 +289,7 @@ func Test_Connect(t *testing.T) {
287289
Commands: rdb.GetCommands(),
288290
BeforeFunc: core.BeforeFuncCombine(
289291
core.BeforeFuncStoreInMeta("username", user),
290-
createInstance("PostgreSQL-15"),
291-
),
292+
fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
292293
Cmd: "scw rdb instance connect {{ .Instance.ID }} username={{ .username }}",
293294
Check: core.TestCheckCombine(
294295
core.TestCheckGolden(),

internal/namespaces/rdb/v1/custom_url_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func Test_UserGetURL(t *testing.T) {
1515
t.Run("Postgres", core.Test(&core.TestConfig{
1616
Commands: rdb.GetCommands(),
1717
BeforeFunc: core.BeforeFuncCombine(
18-
createInstance("PostgreSQL-12"),
18+
fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}"),
1919
),
2020
Cmd: "scw rdb user get-url {{ $.Instance.ID }}",
2121
Check: core.TestCheckCombine(
@@ -34,7 +34,7 @@ func Test_UserGetURL(t *testing.T) {
3434
t.Run("MySQL", core.Test(&core.TestConfig{
3535
Commands: rdb.GetCommands(),
3636
BeforeFunc: core.BeforeFuncCombine(
37-
createInstance("MySQL-8"),
37+
fetchLatestEngine("MySQL"), createInstance("{{.latestEngine}}"),
3838
),
3939
Cmd: "scw rdb user get-url {{ $.Instance.ID }}",
4040
Check: core.TestCheckCombine(
@@ -57,7 +57,7 @@ func Test_UserGetURL(t *testing.T) {
5757
t.Run("With custom user", core.Test(&core.TestConfig{
5858
Commands: rdb.GetCommands(),
5959
BeforeFunc: core.BeforeFuncCombine(
60-
createInstance("PostgreSQL-12"),
60+
fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}"),
6161
core.ExecBeforeCmd(fmt.Sprintf("scw rdb user create instance-id={{ $.Instance.ID }} name=%s password=%s is-admin=false", customUserName, customUserPassword)),
6262
),
6363
Cmd: "scw rdb user get-url {{ $.Instance.ID }} user=" + customUserName,
@@ -77,7 +77,7 @@ func Test_UserGetURL(t *testing.T) {
7777
t.Run("With custom database", core.Test(&core.TestConfig{
7878
Commands: rdb.GetCommands(),
7979
BeforeFunc: core.BeforeFuncCombine(
80-
createInstance("PostgreSQL-12"),
80+
fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}"),
8181
core.ExecBeforeCmd("scw rdb database create instance-id={{ $.Instance.ID }} name="+customDBName),
8282
),
8383
Cmd: "scw rdb user get-url {{ $.Instance.ID }} db=" + customDBName,
@@ -99,7 +99,7 @@ func Test_DatabaseGetURL(t *testing.T) {
9999
t.Run("Postgres", core.Test(&core.TestConfig{
100100
Commands: rdb.GetCommands(),
101101
BeforeFunc: core.BeforeFuncCombine(
102-
createInstance("PostgreSQL-12"),
102+
fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}"),
103103
),
104104
Cmd: "scw rdb database get-url {{ $.Instance.ID }}",
105105
Check: core.TestCheckCombine(

internal/namespaces/rdb/v1/custom_user_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
func Test_ListUser(t *testing.T) {
1212
t.Run("Simple", core.Test(&core.TestConfig{
1313
Commands: rdb.GetCommands(),
14-
BeforeFunc: createInstance("PostgreSQL-12"),
14+
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
1515
Cmd: "scw rdb user list instance-id={{ .Instance.ID }}",
1616
Check: core.TestCheckGolden(),
1717
AfterFunc: deleteInstance(),
@@ -21,15 +21,15 @@ func Test_ListUser(t *testing.T) {
2121
func Test_CreateUser(t *testing.T) {
2222
t.Run("Simple", core.Test(&core.TestConfig{
2323
Commands: rdb.GetCommands(),
24-
BeforeFunc: createInstance("PostgreSQL-12"),
24+
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
2525
Cmd: fmt.Sprintf("scw rdb user create instance-id={{ $.Instance.Instance.ID }} name=%s password=%s", name, password),
2626
Check: core.TestCheckGolden(),
2727
AfterFunc: deleteInstance(),
2828
}))
2929

3030
t.Run("With password generator", core.Test(&core.TestConfig{
3131
Commands: rdb.GetCommands(),
32-
BeforeFunc: createInstance("PostgreSQL-12"),
32+
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
3333
Cmd: fmt.Sprintf("scw rdb user create instance-id={{ $.Instance.Instance.ID }} name=%s generate-password=true", name),
3434
// do not check the golden as the password generated locally and on CI will necessarily be different
3535
Check: core.TestCheckExitCode(0),
@@ -41,7 +41,7 @@ func Test_UpdateUser(t *testing.T) {
4141
t.Run("Simple", core.Test(&core.TestConfig{
4242
Commands: rdb.GetCommands(),
4343
BeforeFunc: core.BeforeFuncCombine(
44-
createInstance("PostgreSQL-12"),
44+
fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}"),
4545
core.ExecBeforeCmd(fmt.Sprintf("scw rdb user create instance-id={{ $.Instance.Instance.ID }} name=%s password=%s", name, password)),
4646
),
4747
Cmd: fmt.Sprintf("scw rdb user update instance-id={{ $.Instance.Instance.ID }} name=%s password=Newp1ssw0rd! is-admin=true", name),
@@ -52,7 +52,7 @@ func Test_UpdateUser(t *testing.T) {
5252
t.Run("With password generator", core.Test(&core.TestConfig{
5353
Commands: rdb.GetCommands(),
5454
BeforeFunc: core.BeforeFuncCombine(
55-
createInstance("PostgreSQL-12"),
55+
fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}"),
5656
core.ExecBeforeCmd(fmt.Sprintf("scw rdb user create instance-id={{ $.Instance.Instance.ID }} name=%s password=%s", name, password)),
5757
),
5858
Cmd: fmt.Sprintf("scw rdb user update instance-id={{ $.Instance.Instance.ID }} name=%s generate-password=true is-admin=true", name),

internal/namespaces/rdb/v1/helper_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/scaleway/scaleway-cli/v2/core"
88
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/rdb/v1"
9+
rdbSDK "github.com/scaleway/scaleway-sdk-go/api/rdb/v1"
910
"github.com/scaleway/scaleway-sdk-go/api/vpc/v2"
1011
"github.com/scaleway/scaleway-sdk-go/scw"
1112
)
@@ -17,6 +18,18 @@ const (
1718
engine = "PostgreSQL-15"
1819
)
1920

21+
func fetchLatestEngine(engine string) core.BeforeFunc {
22+
return func(ctx *core.BeforeFuncCtx) error {
23+
api := rdbSDK.NewAPI(ctx.Client)
24+
dbEngine, err := api.FetchLatestEngineVersion(engine)
25+
if err != nil {
26+
return err
27+
}
28+
ctx.Meta["latestEngine"] = dbEngine.Name
29+
return nil
30+
}
31+
}
32+
2033
func createInstance(engine string) core.BeforeFunc {
2134
return core.ExecStoreBeforeCmd(
2235
"Instance",

0 commit comments

Comments
 (0)