Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(vpc): fix postgres version #4365

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions core/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ func Test(config *TestConfig) func(t *testing.T) {
renderedArgs := []string(nil)
rawArgs := config.Args
if config.Cmd != "" {
renderedArgs = cmdToArgs(meta, config.Cmd)
renderedArgs = CmdToArgs(meta, config.Cmd)
} else {
// We render raw arguments from meta
for _, arg := range rawArgs {
Expand Down Expand Up @@ -491,7 +491,7 @@ func Test(config *TestConfig) func(t *testing.T) {
}
}

func cmdToArgs(meta testMetadata, s string) []string {
func CmdToArgs(meta testMetadata, s string) []string {
return strings.Split(meta.render(s), " ")
}

Expand Down Expand Up @@ -543,7 +543,7 @@ func AfterFuncWhenUpdatingCassette(afterFunc AfterFunc) AfterFunc {
// in the context Meta at metaKey.
func ExecStoreBeforeCmd(metaKey, cmd string) BeforeFunc {
return func(ctx *BeforeFuncCtx) error {
args := cmdToArgs(ctx.Meta, cmd)
args := CmdToArgs(ctx.Meta, cmd)
ctx.Logger.Debugf("ExecStoreBeforeCmd: metaKey=%s args=%s\n", metaKey, args)
ctx.Meta[metaKey] = ctx.ExecuteCmd(args)
return nil
Expand All @@ -560,7 +560,7 @@ func BeforeFuncOsExec(cmd string, args ...string) BeforeFunc {
// ExecBeforeCmd executes the given before command.
func ExecBeforeCmd(cmd string) BeforeFunc {
return func(ctx *BeforeFuncCtx) error {
args := cmdToArgs(ctx.Meta, cmd)
args := CmdToArgs(ctx.Meta, cmd)
ctx.Logger.Debugf("ExecBeforeCmd: args=%s\n", args)
ctx.ExecuteCmd(args)
return nil
Expand All @@ -582,7 +582,7 @@ func ExecBeforeCmdArgs(args []string) BeforeFunc {
// ExecAfterCmd executes the given before command.
func ExecAfterCmd(cmd string) AfterFunc {
return func(ctx *AfterFuncCtx) error {
args := cmdToArgs(ctx.Meta, cmd)
args := CmdToArgs(ctx.Meta, cmd)
ctx.Logger.Debugf("ExecAfterCmd: args=%s\n", args)
ctx.ExecuteCmd(args)
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func Test_GetPrivateNetwork(t *testing.T) {
createNIC(),
createLB(),
attachLB(),
createRdbInstance(),
createRdbInstance("RDB", "PostgreSQL"),
),
Cmd: "scw vpc private-network get {{ .PN.ID }}",
Check: core.TestCheckGolden(),
Expand Down
28 changes: 23 additions & 5 deletions internal/namespaces/vpc/v2/helper_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package vpc_test

import (
"fmt"

"github.com/scaleway/scaleway-cli/v2/core"
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/rdb/v1"
rdbAPI "github.com/scaleway/scaleway-sdk-go/api/rdb/v1"
)

func createInstance() core.BeforeFunc {
Expand Down Expand Up @@ -56,11 +60,25 @@ func deleteLB() core.AfterFunc {
return core.ExecAfterCmd("scw lb lb delete {{ .LB.ID }}")
}

func createRdbInstance() core.BeforeFunc {
return core.ExecStoreBeforeCmd(
"RDB",
"scw rdb instance create node-type=DB-DEV-S is-ha-cluster=false name=cli-test engine=PostgreSQL-12 user-name=foobar password={4xdl*#QOoP+&3XRkGA)] init-endpoints.0.private-network.private-network-id={{ .PN.ID }} init-endpoints.0.private-network.service-ip=192.168.0.1/24 --wait",
)
func createRdbInstance(metaKey, engineName string) core.BeforeFunc {
return func(ctx *core.BeforeFuncCtx) error {
api := rdbAPI.NewAPI(ctx.Client)
engine, err := api.FetchLatestEngineVersion(engineName)
if err != nil {
return err
}
cmd := fmt.Sprintf(
"scw rdb instance create node-type=DB-DEV-S is-ha-cluster=false name=cli-test engine=%s user-name=foobar password={4xdl*#QOoP+&3XRkGA)] init-endpoints.0.private-network.private-network-id={{ .PN.ID }} init-endpoints.0.private-network.service-ip=192.168.0.1/24 --wait",
engine.Name,
)

args := core.CmdToArgs(ctx.Meta, cmd)
res := ctx.ExecuteCmd(args)

instance := res.(rdb.CreateInstanceResult)
ctx.Meta[metaKey] = instance
return nil
}
}

func detachRdbInstance() core.AfterFunc {
Expand Down
Loading
Loading