Skip to content

Commit

Permalink
fix(rdb): update engine
Browse files Browse the repository at this point in the history
  • Loading branch information
jremy42 committed Jan 10, 2025
1 parent 453ebd1 commit a6b42cd
Show file tree
Hide file tree
Showing 100 changed files with 96,749 additions and 29,517 deletions.
18 changes: 9 additions & 9 deletions internal/namespaces/rdb/v1/custom_acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func Test_AddACL(t *testing.T) {
t.Run("Simple", core.Test(&core.TestConfig{
Commands: rdb.GetCommands(),
BeforeFunc: createInstance("PostgreSQL-12"),
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
Cmd: "scw rdb acl add 1.2.3.4 instance-id={{ .Instance.ID }} --wait",
Check: core.TestCheckCombine(
core.TestCheckGolden(),
Expand All @@ -25,7 +25,7 @@ func Test_AddACL(t *testing.T) {

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

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

t.Run("Multiple with description", core.Test(&core.TestConfig{
Commands: rdb.GetCommands(),
BeforeFunc: createInstance("PostgreSQL-12"),
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
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",
Check: core.TestCheckCombine(
core.TestCheckGolden(),
Expand All @@ -69,7 +69,7 @@ func Test_AddACL(t *testing.T) {
func Test_DeleteACL(t *testing.T) {
t.Run("Simple", core.Test(&core.TestConfig{
Commands: rdb.GetCommands(),
BeforeFunc: createInstance("PostgreSQL-12"),
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
Cmd: "scw rdb acl delete 0.0.0.0/0 instance-id={{ .Instance.ID }} --wait",
Check: core.TestCheckCombine(
core.TestCheckGolden(),
Expand All @@ -84,7 +84,7 @@ func Test_DeleteACL(t *testing.T) {
t.Run("Multiple when set", core.Test(&core.TestConfig{
Commands: rdb.GetCommands(),
BeforeFunc: core.BeforeFuncCombine(
createInstance("PostgreSQL-12"),
fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}"),
core.ExecBeforeCmd("scw rdb acl add 1.2.3.4 192.168.1.0/32 10.10.10.10 instance-id={{ .Instance.ID }} --wait"),
),
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",
Expand All @@ -101,7 +101,7 @@ func Test_DeleteACL(t *testing.T) {
t.Run("Multiple when not set", core.Test(&core.TestConfig{
Commands: rdb.GetCommands(),
BeforeFunc: core.BeforeFuncCombine(
createInstance("PostgreSQL-12"),
fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}"),
core.ExecBeforeCmd("scw rdb acl add 192.168.1.0/32 instance-id={{ .Instance.ID }} --wait"),
),
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",
Expand All @@ -119,7 +119,7 @@ func Test_DeleteACL(t *testing.T) {
func Test_SetACL(t *testing.T) {
t.Run("Simple", core.Test(&core.TestConfig{
Commands: rdb.GetCommands(),
BeforeFunc: createInstance("PostgreSQL-12"),
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
Cmd: "scw rdb acl set 1.2.3.4 instance-id={{ .Instance.ID }} descriptions.0=something --wait",
Check: core.TestCheckCombine(
core.TestCheckGolden(),
Expand All @@ -136,7 +136,7 @@ func Test_SetACL(t *testing.T) {
t.Run("Multiple", core.Test(&core.TestConfig{
Commands: rdb.GetCommands(),
BeforeFunc: core.BeforeFuncCombine(
createInstance("PostgreSQL-12"),
fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}"),
core.ExecBeforeCmd("scw rdb acl add 1.2.3.4 192.168.1.0/32 10.10.10.10 instance-id={{ .Instance.ID }} --wait"),
),
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",
Expand Down
6 changes: 3 additions & 3 deletions internal/namespaces/rdb/v1/custom_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func Test_EndpointCreate(t *testing.T) {
Commands: cmds,
BeforeFunc: core.BeforeFuncCombine(
createPN(),
createInstance("PostgreSQL-15"),
fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}"),
),
Cmd: "scw rdb endpoint create {{ .Instance.ID }} private-network.private-network-id={{ .PN.ID }} private-network.service-ip={{ .IPNet }} --wait",
Check: core.TestCheckCombine(
Expand All @@ -58,7 +58,7 @@ func Test_EndpointCreate(t *testing.T) {
Commands: cmds,
BeforeFunc: core.BeforeFuncCombine(
createPN(),
createInstance("PostgreSQL-15"),
fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}"),
),
Cmd: "scw rdb endpoint create {{ .Instance.ID }} private-network.private-network-id={{ .PN.ID }} private-network.enable-ipam=true --wait",
Check: core.TestCheckCombine(
Expand Down Expand Up @@ -127,7 +127,7 @@ func Test_EndpointDelete(t *testing.T) {
t.Run("All", core.Test(&core.TestConfig{
Commands: cmds,
BeforeFunc: core.BeforeFuncCombine(
createInstance("PostgreSQL-15"),
fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}"),
listEndpointsInMeta(),
),
Cmd: "scw rdb endpoint delete {{ .PublicEndpoint.ID }} instance-id={{ .Instance.ID }} --wait",
Expand Down
25 changes: 13 additions & 12 deletions internal/namespaces/rdb/v1/custom_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
func Test_ListInstance(t *testing.T) {
t.Run("Simple", core.Test(&core.TestConfig{
Commands: rdb.GetCommands(),
BeforeFunc: createInstance("PostgreSQL-12"),
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
Cmd: "scw rdb instance list",
Check: core.TestCheckGolden(),
AfterFunc: deleteInstance(),
Expand All @@ -35,7 +35,7 @@ func Test_ListInstance(t *testing.T) {
func Test_CloneInstance(t *testing.T) {
t.Run("Simple", core.Test(&core.TestConfig{
Commands: rdb.GetCommands(),
BeforeFunc: createInstance("PostgreSQL-12"),
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
Cmd: "scw rdb instance clone {{ .Instance.ID }} node-type=DB-DEV-M name=foobar --wait",
Check: core.TestCheckGolden(),
AfterFunc: deleteInstance(),
Expand Down Expand Up @@ -153,7 +153,7 @@ func Test_CreateInstanceInitEndpoints(t *testing.T) {
func Test_GetInstance(t *testing.T) {
t.Run("Simple", core.Test(&core.TestConfig{
Commands: rdb.GetCommands(),
BeforeFunc: createInstance("PostgreSQL-12"),
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
Cmd: "scw rdb instance get {{ .Instance.ID }}",
Check: core.TestCheckGolden(),
AfterFunc: deleteInstance(),
Expand All @@ -163,7 +163,7 @@ func Test_GetInstance(t *testing.T) {
func Test_UpgradeInstance(t *testing.T) {
t.Run("Simple", core.Test(&core.TestConfig{
Commands: rdb.GetCommands(),
BeforeFunc: createInstance("PostgreSQL-12"),
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
Cmd: "scw rdb instance upgrade {{ .Instance.ID }} node-type=DB-DEV-M --wait",
Check: core.TestCheckGolden(),
AfterFunc: deleteInstance(),
Expand All @@ -173,7 +173,7 @@ func Test_UpgradeInstance(t *testing.T) {
func Test_UpdateInstance(t *testing.T) {
t.Run("Update instance name", core.Test(&core.TestConfig{
Commands: rdb.GetCommands(),
BeforeFunc: createInstance("PostgreSQL-12"),
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
Cmd: "scw rdb instance update {{ .Instance.ID }} name=foo --wait",
Check: core.TestCheckCombine(
func(t *testing.T, ctx *core.CheckFuncCtx) {
Expand All @@ -188,7 +188,7 @@ func Test_UpdateInstance(t *testing.T) {

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

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

t.Run("Modify default work_mem from 4 to 8 MB", core.Test(&core.TestConfig{
Commands: rdb.GetCommands(),
BeforeFunc: createInstance("PostgreSQL-12"),
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
Cmd: "scw rdb instance update {{ .Instance.ID }} settings.0.name=work_mem settings.0.value=8 --wait",
Check: core.TestCheckCombine(
func(t *testing.T, ctx *core.CheckFuncCtx) {
Expand All @@ -236,7 +236,8 @@ func Test_UpdateInstance(t *testing.T) {
t.Run("Modify 3 settings + add a new one", core.Test(&core.TestConfig{
Commands: rdb.GetCommands(),
BeforeFunc: core.BeforeFuncCombine(
createInstance("PostgreSQL-12"),
fetchLatestEngine("PostgreSQL"),
createInstance("{{.latestEngine}}"),
core.ExecBeforeCmd("scw rdb instance update {{ .Instance.ID }} settings.0.name=work_mem settings.0.value=8"+
" settings.1.name=max_connections settings.1.value=200"+
" settings.2.name=effective_cache_size settings.2.value=1000"+
Expand Down Expand Up @@ -272,7 +273,8 @@ func Test_Connect(t *testing.T) {
Commands: rdb.GetCommands(),
BeforeFunc: core.BeforeFuncCombine(
core.BeforeFuncStoreInMeta("username", user),
createInstance("MySQL-8"),
fetchLatestEngine("MySQL"),
createInstance("{{.latestEngine}}"),
),
Cmd: "scw rdb instance connect {{ .Instance.ID }} username={{ .username }}",
Check: core.TestCheckCombine(
Expand All @@ -287,8 +289,7 @@ func Test_Connect(t *testing.T) {
Commands: rdb.GetCommands(),
BeforeFunc: core.BeforeFuncCombine(
core.BeforeFuncStoreInMeta("username", user),
createInstance("PostgreSQL-15"),
),
fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
Cmd: "scw rdb instance connect {{ .Instance.ID }} username={{ .username }}",
Check: core.TestCheckCombine(
core.TestCheckGolden(),
Expand Down
10 changes: 5 additions & 5 deletions internal/namespaces/rdb/v1/custom_url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func Test_UserGetURL(t *testing.T) {
t.Run("Postgres", core.Test(&core.TestConfig{
Commands: rdb.GetCommands(),
BeforeFunc: core.BeforeFuncCombine(
createInstance("PostgreSQL-12"),
fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}"),
),
Cmd: "scw rdb user get-url {{ $.Instance.ID }}",
Check: core.TestCheckCombine(
Expand All @@ -34,7 +34,7 @@ func Test_UserGetURL(t *testing.T) {
t.Run("MySQL", core.Test(&core.TestConfig{
Commands: rdb.GetCommands(),
BeforeFunc: core.BeforeFuncCombine(
createInstance("MySQL-8"),
fetchLatestEngine("MySQL"), createInstance("{{.latestEngine}}"),
),
Cmd: "scw rdb user get-url {{ $.Instance.ID }}",
Check: core.TestCheckCombine(
Expand All @@ -57,7 +57,7 @@ func Test_UserGetURL(t *testing.T) {
t.Run("With custom user", core.Test(&core.TestConfig{
Commands: rdb.GetCommands(),
BeforeFunc: core.BeforeFuncCombine(
createInstance("PostgreSQL-12"),
fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}"),
core.ExecBeforeCmd(fmt.Sprintf("scw rdb user create instance-id={{ $.Instance.ID }} name=%s password=%s is-admin=false", customUserName, customUserPassword)),
),
Cmd: "scw rdb user get-url {{ $.Instance.ID }} user=" + customUserName,
Expand All @@ -77,7 +77,7 @@ func Test_UserGetURL(t *testing.T) {
t.Run("With custom database", core.Test(&core.TestConfig{
Commands: rdb.GetCommands(),
BeforeFunc: core.BeforeFuncCombine(
createInstance("PostgreSQL-12"),
fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}"),
core.ExecBeforeCmd("scw rdb database create instance-id={{ $.Instance.ID }} name="+customDBName),
),
Cmd: "scw rdb user get-url {{ $.Instance.ID }} db=" + customDBName,
Expand All @@ -99,7 +99,7 @@ func Test_DatabaseGetURL(t *testing.T) {
t.Run("Postgres", core.Test(&core.TestConfig{
Commands: rdb.GetCommands(),
BeforeFunc: core.BeforeFuncCombine(
createInstance("PostgreSQL-12"),
fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}"),
),
Cmd: "scw rdb database get-url {{ $.Instance.ID }}",
Check: core.TestCheckCombine(
Expand Down
10 changes: 5 additions & 5 deletions internal/namespaces/rdb/v1/custom_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func Test_ListUser(t *testing.T) {
t.Run("Simple", core.Test(&core.TestConfig{
Commands: rdb.GetCommands(),
BeforeFunc: createInstance("PostgreSQL-12"),
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
Cmd: "scw rdb user list instance-id={{ .Instance.ID }}",
Check: core.TestCheckGolden(),
AfterFunc: deleteInstance(),
Expand All @@ -21,15 +21,15 @@ func Test_ListUser(t *testing.T) {
func Test_CreateUser(t *testing.T) {
t.Run("Simple", core.Test(&core.TestConfig{
Commands: rdb.GetCommands(),
BeforeFunc: createInstance("PostgreSQL-12"),
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
Cmd: fmt.Sprintf("scw rdb user create instance-id={{ $.Instance.Instance.ID }} name=%s password=%s", name, password),
Check: core.TestCheckGolden(),
AfterFunc: deleteInstance(),
}))

t.Run("With password generator", core.Test(&core.TestConfig{
Commands: rdb.GetCommands(),
BeforeFunc: createInstance("PostgreSQL-12"),
BeforeFunc: core.BeforeFuncCombine(fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}")),
Cmd: fmt.Sprintf("scw rdb user create instance-id={{ $.Instance.Instance.ID }} name=%s generate-password=true", name),
// do not check the golden as the password generated locally and on CI will necessarily be different
Check: core.TestCheckExitCode(0),
Expand All @@ -41,7 +41,7 @@ func Test_UpdateUser(t *testing.T) {
t.Run("Simple", core.Test(&core.TestConfig{
Commands: rdb.GetCommands(),
BeforeFunc: core.BeforeFuncCombine(
createInstance("PostgreSQL-12"),
fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}"),
core.ExecBeforeCmd(fmt.Sprintf("scw rdb user create instance-id={{ $.Instance.Instance.ID }} name=%s password=%s", name, password)),
),
Cmd: fmt.Sprintf("scw rdb user update instance-id={{ $.Instance.Instance.ID }} name=%s password=Newp1ssw0rd! is-admin=true", name),
Expand All @@ -52,7 +52,7 @@ func Test_UpdateUser(t *testing.T) {
t.Run("With password generator", core.Test(&core.TestConfig{
Commands: rdb.GetCommands(),
BeforeFunc: core.BeforeFuncCombine(
createInstance("PostgreSQL-12"),
fetchLatestEngine("PostgreSQL"), createInstance("{{.latestEngine}}"),
core.ExecBeforeCmd(fmt.Sprintf("scw rdb user create instance-id={{ $.Instance.Instance.ID }} name=%s password=%s", name, password)),
),
Cmd: fmt.Sprintf("scw rdb user update instance-id={{ $.Instance.Instance.ID }} name=%s generate-password=true is-admin=true", name),
Expand Down
13 changes: 13 additions & 0 deletions internal/namespaces/rdb/v1/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/scaleway/scaleway-cli/v2/core"
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/rdb/v1"
rdbSDK "github.com/scaleway/scaleway-sdk-go/api/rdb/v1"
"github.com/scaleway/scaleway-sdk-go/api/vpc/v2"
"github.com/scaleway/scaleway-sdk-go/scw"
)
Expand All @@ -17,6 +18,18 @@ const (
engine = "PostgreSQL-15"
)

func fetchLatestEngine(engine string) core.BeforeFunc {
return func(ctx *core.BeforeFuncCtx) error {
api := rdbSDK.NewAPI(ctx.Client)
dbEngine, err := api.FetchLatestEngineVersion(engine)
if err != nil {
return err
}
ctx.Meta["latestEngine"] = dbEngine.Name
return nil
}
}

func createInstance(engine string) core.BeforeFunc {
return core.ExecStoreBeforeCmd(
"Instance",
Expand Down
Loading

0 comments on commit a6b42cd

Please sign in to comment.