From 0891ef062e35c975d9907f576ac44e64bcd5ee5e Mon Sep 17 00:00:00 2001 From: ramya-bangera Date: Thu, 17 Oct 2024 10:49:16 +0530 Subject: [PATCH 1/4] Fix the lint issues 1. fix errcheck in main.go - check return value of `viper.BindPFlags` 2. fix v in config.go - added nolint to config.go to escape from lint issues as it contains unused variables. This file can even be removed from repo if not needed --- cmd/migrate/config.go | 1 + cmd/migrate/main.go | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/migrate/config.go b/cmd/migrate/config.go index a03097618..a0ed649c1 100644 --- a/cmd/migrate/config.go +++ b/cmd/migrate/config.go @@ -1,3 +1,4 @@ +//nolint:unused package main import "github.com/spf13/pflag" diff --git a/cmd/migrate/main.go b/cmd/migrate/main.go index b6188d95f..21291698c 100644 --- a/cmd/migrate/main.go +++ b/cmd/migrate/main.go @@ -16,7 +16,10 @@ import ( func init() { pflag.Parse() - viper.BindPFlags(pflag.CommandLine) + err := viper.BindPFlags(pflag.CommandLine) + if err != nil { + log.Fatalf("failed to bind full flag set to config: %v", err) + } viper.AutomaticEnv() viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) viper.AddConfigPath(viper.GetString("config.source")) From e1e3a421915b254f71bf7ec111d3655285cc4fd8 Mon Sep 17 00:00:00 2001 From: Dale Hui Date: Fri, 30 Aug 2024 11:53:21 -0700 Subject: [PATCH 2/4] Fix redshift tests Newer versions of postgres require a password --- database/redshift/redshift_test.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/database/redshift/redshift_test.go b/database/redshift/redshift_test.go index 944a6add3..a536041db 100644 --- a/database/redshift/redshift_test.go +++ b/database/redshift/redshift_test.go @@ -28,8 +28,17 @@ import ( _ "github.com/golang-migrate/migrate/v4/source/file" ) +const ( + pgPassword = "redshift" +) + var ( - opts = dktest.Options{PortRequired: true, ReadyFunc: isReady} + opts = dktest.Options{ + Env: map[string]string{"POSTGRES_PASSWORD": pgPassword}, + PortRequired: true, + ReadyFunc: isReady, + } + specs = []dktesting.ContainerSpec{ {ImageName: "postgres:8", Options: opts}, } @@ -44,7 +53,7 @@ func pgConnectionString(host, port string) string { } func connectionString(schema, host, port string) string { - return fmt.Sprintf("%s://postgres@%s:%s/postgres?sslmode=disable", schema, host, port) + return fmt.Sprintf("%s://postgres:%s@%s:%s/postgres?sslmode=disable", schema, pgPassword, host, port) } func isReady(ctx context.Context, c dktest.ContainerInfo) bool { @@ -192,7 +201,7 @@ func TestFilterCustomQuery(t *testing.T) { t.Fatal(err) } - addr := fmt.Sprintf("postgres://postgres@%v:%v/postgres?sslmode=disable&x-custom=foobar", ip, port) + addr := fmt.Sprintf("postgres://postgres:%s@%v:%v/postgres?sslmode=disable&x-custom=foobar", pgPassword, ip, port) p := &Redshift{} d, err := p.Open(addr) if err != nil { @@ -234,7 +243,7 @@ func TestWithSchema(t *testing.T) { } // re-connect using that schema - d2, err := p.Open(fmt.Sprintf("postgres://postgres@%v:%v/postgres?sslmode=disable&search_path=foobar", ip, port)) + d2, err := p.Open(fmt.Sprintf("postgres://postgres:%s@%v:%v/postgres?sslmode=disable&search_path=foobar", pgPassword, ip, port)) if err != nil { t.Fatal(err) } From 0e8dc7cdf158aae10b6b391d8a3e01710a300faf Mon Sep 17 00:00:00 2001 From: Dale Hui Date: Thu, 5 Sep 2024 23:22:36 -0700 Subject: [PATCH 3/4] Use forked version of postgres 8 to avoid Docker image format version issues. See: https://docs.docker.com/engine/deprecated/#pushing-and-pulling-with-image-manifest-v2-schema-1 Forked images created by pulling the original image and pushing to the fork. For more details, see: https://github.com/golang-migrate/migrate/pull/1143#issuecomment-2328069381 --- database/redshift/redshift_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/redshift/redshift_test.go b/database/redshift/redshift_test.go index a536041db..9ee5cbe64 100644 --- a/database/redshift/redshift_test.go +++ b/database/redshift/redshift_test.go @@ -40,7 +40,7 @@ var ( } specs = []dktesting.ContainerSpec{ - {ImageName: "postgres:8", Options: opts}, + {ImageName: "migrate/postgres8:8", Options: opts}, } ) From 69bfe090a598946c1353e730f62e06a2e4dd21fd Mon Sep 17 00:00:00 2001 From: Dale Hui Date: Sun, 25 Aug 2024 17:29:12 -0700 Subject: [PATCH 4/4] Use newer math/rand/v2 --- testing/docker.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/testing/docker.go b/testing/docker.go index 2a7c57f98..d418f3568 100644 --- a/testing/docker.go +++ b/testing/docker.go @@ -15,11 +15,10 @@ import ( dockerclient "github.com/docker/docker/client" "github.com/hashicorp/go-multierror" "io" - "math/rand" + "math/rand/v2" "strconv" "strings" "testing" - "time" ) func NewDockerContainer(t testing.TB, image string, env []string, cmd []string) (*DockerContainer, error) { @@ -286,15 +285,11 @@ type dockerImagePullOutput struct { Progress string `json:"progress"` } -func init() { - rand.Seed(time.Now().UnixNano()) -} - func pseudoRandStr(n int) string { var letterRunes = []rune("abcdefghijklmnopqrstuvwxyz0123456789") b := make([]rune, n) for i := range b { - b[i] = letterRunes[rand.Intn(len(letterRunes))] + b[i] = letterRunes[rand.IntN(len(letterRunes))] } return string(b) }