From c00e9874e83609d74dcc27fc05d85c025c6b04e0 Mon Sep 17 00:00:00 2001 From: Felix Hoffmann <19827840+zzzFelix@users.noreply.github.com> Date: Fri, 10 May 2024 08:36:03 +0200 Subject: [PATCH 01/12] feat: make encoding configurable in initdb (#133) --- config.go | 7 +++++++ embedded_postgres.go | 2 +- embedded_postgres_test.go | 35 +++++++++++++++++++++++++++++++++-- prepare_database.go | 8 ++++++-- prepare_database_test.go | 27 ++++++++++++++++++++++++--- 5 files changed, 71 insertions(+), 8 deletions(-) diff --git a/config.go b/config.go index 75d4f64..3396fe0 100644 --- a/config.go +++ b/config.go @@ -19,6 +19,7 @@ type Config struct { dataPath string binariesPath string locale string + encoding string startParameters map[string]string binaryRepositoryURL string startTimeout time.Duration @@ -110,6 +111,12 @@ func (c Config) Locale(locale string) Config { return c } +// Encoding sets the default character set for initdb +func (c Config) Encoding(encoding string) Config { + c.encoding = encoding + return c +} + // StartParameters sets run-time parameters when starting Postgres (passed to Postgres via "-c"). // // These parameters can be used to override the default configuration values in postgres.conf such diff --git a/embedded_postgres.go b/embedded_postgres.go index d3af5f6..fcf98d1 100644 --- a/embedded_postgres.go +++ b/embedded_postgres.go @@ -167,7 +167,7 @@ func (ep *EmbeddedPostgres) cleanDataDirectoryAndInit() error { return fmt.Errorf("unable to clean up data directory %s with error: %s", ep.config.dataPath, err) } - if err := ep.initDatabase(ep.config.binariesPath, ep.config.runtimePath, ep.config.dataPath, ep.config.username, ep.config.password, ep.config.locale, ep.syncedLogger.file); err != nil { + if err := ep.initDatabase(ep.config.binariesPath, ep.config.runtimePath, ep.config.dataPath, ep.config.username, ep.config.password, ep.config.locale, ep.config.encoding, ep.syncedLogger.file); err != nil { return err } diff --git a/embedded_postgres_test.go b/embedded_postgres_test.go index 474cd2a..bb4ee53 100644 --- a/embedded_postgres_test.go +++ b/embedded_postgres_test.go @@ -123,7 +123,7 @@ func Test_ErrorWhenUnableToInitDatabase(t *testing.T) { return jarFile, true } - database.initDatabase = func(binaryExtractLocation, runtimePath, dataLocation, username, password, locale string, logger *os.File) error { + database.initDatabase = func(binaryExtractLocation, runtimePath, dataLocation, username, password, locale string, encoding string, logger *os.File) error { return errors.New("ah it did not work") } @@ -226,7 +226,7 @@ func Test_ErrorWhenCannotStartPostgresProcess(t *testing.T) { return jarFile, true } - database.initDatabase = func(binaryExtractLocation, runtimePath, dataLocation, username, password, locale string, logger *os.File) error { + database.initDatabase = func(binaryExtractLocation, runtimePath, dataLocation, username, password, locale string, encoding string, logger *os.File) error { _, _ = logger.Write([]byte("ah it did not work")) return nil } @@ -257,6 +257,7 @@ func Test_CustomConfig(t *testing.T) { Port(9876). StartTimeout(10 * time.Second). Locale("C"). + Encoding("UTF8"). Logger(nil)) if err := database.Start(); err != nil { @@ -356,6 +357,36 @@ func Test_CustomLocaleConfig(t *testing.T) { } } +func Test_CustomEncodingConfig(t *testing.T) { + database := NewDatabase(DefaultConfig().Encoding("UTF8")) + if err := database.Start(); err != nil { + shutdownDBAndFail(t, err, database) + } + + db, err := sql.Open("postgres", "host=localhost port=5432 user=postgres password=postgres dbname=postgres sslmode=disable") + if err != nil { + shutdownDBAndFail(t, err, database) + } + + rows := db.QueryRow("SHOW SERVER_ENCODING;") + + var ( + value string + ) + if err := rows.Scan(&value); err != nil { + shutdownDBAndFail(t, err, database) + } + assert.Equal(t, "UTF8", value) + + if err := db.Close(); err != nil { + shutdownDBAndFail(t, err, database) + } + + if err := database.Stop(); err != nil { + shutdownDBAndFail(t, err, database) + } +} + func Test_ConcurrentStart(t *testing.T) { var wg sync.WaitGroup diff --git a/prepare_database.go b/prepare_database.go index 0e8fa65..751aaea 100644 --- a/prepare_database.go +++ b/prepare_database.go @@ -18,10 +18,10 @@ const ( fmtAfterError = "%v happened after error: %w" ) -type initDatabase func(binaryExtractLocation, runtimePath, pgDataDir, username, password, locale string, logger *os.File) error +type initDatabase func(binaryExtractLocation, runtimePath, pgDataDir, username, password, locale string, encoding string, logger *os.File) error type createDatabase func(port uint32, username, password, database string) error -func defaultInitDatabase(binaryExtractLocation, runtimePath, pgDataDir, username, password, locale string, logger *os.File) error { +func defaultInitDatabase(binaryExtractLocation, runtimePath, pgDataDir, username, password, locale string, encoding string, logger *os.File) error { passwordFile, err := createPasswordFile(runtimePath, password) if err != nil { return err @@ -38,6 +38,10 @@ func defaultInitDatabase(binaryExtractLocation, runtimePath, pgDataDir, username args = append(args, fmt.Sprintf("--locale=%s", locale)) } + if encoding != "" { + args = append(args, fmt.Sprintf("--encoding=%s", encoding)) + } + postgresInitDBBinary := filepath.Join(binaryExtractLocation, "bin/initdb") postgresInitDBProcess := exec.Command(postgresInitDBBinary, args...) postgresInitDBProcess.Stderr = logger diff --git a/prepare_database_test.go b/prepare_database_test.go index cad9873..2700d27 100644 --- a/prepare_database_test.go +++ b/prepare_database_test.go @@ -12,7 +12,7 @@ import ( ) func Test_defaultInitDatabase_ErrorWhenCannotCreatePasswordFile(t *testing.T) { - err := defaultInitDatabase("path_not_exists", "path_not_exists", "path_not_exists", "Tom", "Beer", "", os.Stderr) + err := defaultInitDatabase("path_not_exists", "path_not_exists", "path_not_exists", "Tom", "Beer", "", "", os.Stderr) assert.EqualError(t, err, "unable to write password file to path_not_exists/pwfile") } @@ -49,7 +49,7 @@ func Test_defaultInitDatabase_ErrorWhenCannotStartInitDBProcess(t *testing.T) { _, _ = logFile.Write([]byte("and here are the logs!")) - err = defaultInitDatabase(binTempDir, runtimeTempDir, filepath.Join(runtimeTempDir, "data"), "Tom", "Beer", "", logFile) + err = defaultInitDatabase(binTempDir, runtimeTempDir, filepath.Join(runtimeTempDir, "data"), "Tom", "Beer", "", "", logFile) assert.NotNil(t, err) assert.Contains(t, err.Error(), fmt.Sprintf("unable to init database using '%s/bin/initdb -A password -U Tom -D %s/data --pwfile=%s/pwfile'", @@ -72,7 +72,7 @@ func Test_defaultInitDatabase_ErrorInvalidLocaleSetting(t *testing.T) { } }() - err = defaultInitDatabase(tempDir, tempDir, filepath.Join(tempDir, "data"), "postgres", "postgres", "en_XY", os.Stderr) + err = defaultInitDatabase(tempDir, tempDir, filepath.Join(tempDir, "data"), "postgres", "postgres", "en_XY", "", os.Stderr) assert.NotNil(t, err) assert.Contains(t, err.Error(), fmt.Sprintf("unable to init database using '%s/bin/initdb -A password -U postgres -D %s/data --pwfile=%s/pwfile --locale=en_XY'", @@ -81,6 +81,27 @@ func Test_defaultInitDatabase_ErrorInvalidLocaleSetting(t *testing.T) { tempDir)) } +func Test_defaultInitDatabase_ErrorInvalidEncodingSetting(t *testing.T) { + tempDir, err := os.MkdirTemp("", "prepare_database_test") + if err != nil { + panic(err) + } + + defer func() { + if err := os.RemoveAll(tempDir); err != nil { + panic(err) + } + }() + + err = defaultInitDatabase(tempDir, tempDir, filepath.Join(tempDir, "data"), "postgres", "postgres", "", "invalid", os.Stderr) + + assert.NotNil(t, err) + assert.Contains(t, err.Error(), fmt.Sprintf("unable to init database using '%s/bin/initdb -A password -U postgres -D %s/data --pwfile=%s/pwfile --encoding=invalid'", + tempDir, + tempDir, + tempDir)) +} + func Test_defaultInitDatabase_PwFileRemoved(t *testing.T) { tempDir, err := os.MkdirTemp("", "prepare_database_test") if err != nil { From 234c60561f317c6b8cba66262122916358146326 Mon Sep 17 00:00:00 2001 From: Philipp Trulson Date: Fri, 10 May 2024 08:40:42 +0200 Subject: [PATCH 02/12] Update build & test workflows (#136) --- .circleci/config.yml | 4 ++-- .github/workflows/build.yml | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d650631..c83551e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2.1 executors: linux-arm64: machine: - image: ubuntu-2004:2022.04.1 + image: ubuntu-2204:2024.01.2 resource_class: arm.medium working_directory: /home/circleci/go/src/github.com/fergusstrange/embedded-postgres apple-m1: &macos-executor @@ -10,7 +10,7 @@ executors: macos: xcode: "14.2.0" orbs: - go: circleci/go@1.7.3 + go: circleci/go@1.11.0 jobs: platform_test: parameters: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e85d739..baad6bc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,11 +11,11 @@ jobs: steps: - name: Checkout id: go - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Set Up Golang - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: - go-version: 1.18 + go-version: 1.22 - name: Check Dependencies run: | go list -json -deps > go.list @@ -37,7 +37,7 @@ jobs: - name: Nancy Vulnerability uses: sonatype-nexus-community/nancy-github-action@main with: - nancyVersion: v1.0.36 + nancyVersion: v1.0.46 nancyCommand: sleuth - name: GolangCI Lint run: | @@ -53,14 +53,14 @@ jobs: - name: Upload Coverage Report env: COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: GO111MODULE=off go get github.com/mattn/goveralls && $(go env GOPATH)/bin/goveralls -v -coverprofile=coverage.out -service=github + run: go install github.com/mattn/goveralls@latest && $(go env GOPATH)/bin/goveralls -v -coverprofile=coverage.out -service=github alpine_tests: name: Alpine Linux Platform Tests runs-on: ubuntu-latest container: - image: golang:1.18-alpine + image: golang:1.22-alpine steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - name: Set Up run: | apk add --upgrade gcc g++ && \ @@ -75,11 +75,11 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Set Up Golang - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: - go-version: 1.18 + go-version: 1.22 - name: Platform Tests run: | cd platform-test From a3b80e3a5159562046ac0fe29c8f28e1e98000e7 Mon Sep 17 00:00:00 2001 From: ferguss Date: Fri, 10 May 2024 17:12:03 +1000 Subject: [PATCH 03/12] Update docs --- README.md | 8 ++++++-- config.go | 2 +- embedded_postgres_test.go | 5 +---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5fa28f8..aff90c2 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,9 @@ This library aims to require as little configuration as possible, favouring over | Password | postgres | | Database | postgres | | Version | 15.3.0 | +| Encoding | UTF8 | +| Locale | C | +| Version | 15.3.0 | | CachePath | $USER_HOME/.embedded-postgres-go/ | | RuntimePath | $USER_HOME/.embedded-postgres-go/extracted | | DataPath | $USER_HOME/.embedded-postgres-go/extracted/data | @@ -49,6 +52,7 @@ This library aims to require as little configuration as possible, favouring over | BinaryRepositoryURL | https://repo1.maven.org/maven2 | | Port | 5432 | | StartTimeout | 15 Seconds | +| StartParameters | map[string]string{"max_connections": "101"} | The *RuntimePath* directory is erased and recreated at each `Start()` and therefore not suitable for persistent data. @@ -85,10 +89,10 @@ Password("wine"). Database("gin"). Version(V12). RuntimePath("/tmp"). -BinaryRepositoryURL("https://repo.local/central.proxy"). +BinaryRepositoryURL("https://repo.local/central.proxy"). Port(9876). StartTimeout(45 * time.Second). -StartParameters(map[string]string{"max_connections": "200"}). +StartParameters(map[string]string{"max_connections": "200"}). Logger(logger)) err := postgres.Start() diff --git a/config.go b/config.go index 3396fe0..97e48d0 100644 --- a/config.go +++ b/config.go @@ -28,7 +28,7 @@ type Config struct { // DefaultConfig provides a default set of configuration to be used "as is" or modified using the provided builders. // The following can be assumed as defaults: -// Version: 15 +// Version: 16 // Port: 5432 // Database: postgres // Username: postgres diff --git a/embedded_postgres_test.go b/embedded_postgres_test.go index bb4ee53..a6b4bd2 100644 --- a/embedded_postgres_test.go +++ b/embedded_postgres_test.go @@ -448,10 +448,7 @@ func Test_ConcurrentStart(t *testing.T) { } func Test_CustomStartParameters(t *testing.T) { - database := NewDatabase(DefaultConfig().StartParameters(map[string]string{ - "max_connections": "101", - "shared_buffers": "16 MB", // Ensure a parameter with spaces encodes correctly. - })) + database := NewDatabase(DefaultConfig().StartParameters(map[string]string{"max_connections": "101"})) if err := database.Start(); err != nil { shutdownDBAndFail(t, err, database) } From efb8f5554a17428524fc8e5ba965513fe0356329 Mon Sep 17 00:00:00 2001 From: ferguss Date: Fri, 10 May 2024 17:13:31 +1000 Subject: [PATCH 04/12] Purge unused files. --- cmd/main.go | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 cmd/main.go diff --git a/cmd/main.go b/cmd/main.go deleted file mode 100644 index 6ef68a1..0000000 --- a/cmd/main.go +++ /dev/null @@ -1,20 +0,0 @@ -package main - -import ( - "log" - - embeddedpostgres "github.com/fergusstrange/embedded-postgres" -) - -func main() { - embeddedPostgres := embeddedpostgres.NewDatabase() - if err := embeddedPostgres.Start(); err != nil { - log.Fatal(err) - } - - defer func() { - if err := embeddedPostgres.Stop(); err != nil { - log.Fatal(err) - } - }() -} From ae9f98f4b210fa076c28ba04079d931fee32c5fe Mon Sep 17 00:00:00 2001 From: Fergus Strange Date: Sun, 28 Jul 2024 15:21:30 +1000 Subject: [PATCH 05/12] Upgrade versions (#140) * Upgrade versions * Update build version --------- Co-authored-by: ferguss --- .github/workflows/build.yml | 2 +- config.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index baad6bc..b64ec69 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -71,7 +71,7 @@ jobs: name: Platform tests strategy: matrix: - os: [ ubuntu-latest, windows-latest, macos-11 ] + os: [ ubuntu-latest, windows-latest, macos-14 ] runs-on: ${{ matrix.os }} steps: - name: Checkout diff --git a/config.go b/config.go index 97e48d0..00faebd 100644 --- a/config.go +++ b/config.go @@ -153,11 +153,11 @@ type PostgresVersion string // Predefined supported Postgres versions. const ( - V16 = PostgresVersion("16.2.0") - V15 = PostgresVersion("15.6.0") - V14 = PostgresVersion("14.11.0") - V13 = PostgresVersion("13.14.0") - V12 = PostgresVersion("12.17.0") + V16 = PostgresVersion("16.3.0") + V15 = PostgresVersion("15.7.0") + V14 = PostgresVersion("14.12.0") + V13 = PostgresVersion("13.15.0") + V12 = PostgresVersion("12.19.0") V11 = PostgresVersion("11.22.0") V10 = PostgresVersion("10.23.0") V9 = PostgresVersion("9.6.24") From 06253c602c124d13b972ed0dc7ca181923a1ee36 Mon Sep 17 00:00:00 2001 From: Fergus Strange Date: Mon, 26 Aug 2024 20:24:45 +1000 Subject: [PATCH 06/12] Update versions (#142) Co-authored-by: ferguss --- config.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/config.go b/config.go index 00faebd..35e9a98 100644 --- a/config.go +++ b/config.go @@ -153,11 +153,11 @@ type PostgresVersion string // Predefined supported Postgres versions. const ( - V16 = PostgresVersion("16.3.0") - V15 = PostgresVersion("15.7.0") - V14 = PostgresVersion("14.12.0") - V13 = PostgresVersion("13.15.0") - V12 = PostgresVersion("12.19.0") + V16 = PostgresVersion("16.4.0") + V15 = PostgresVersion("15.8.0") + V14 = PostgresVersion("14.13.0") + V13 = PostgresVersion("13.16.0") + V12 = PostgresVersion("12.20.0") V11 = PostgresVersion("11.22.0") V10 = PostgresVersion("10.23.0") V9 = PostgresVersion("9.6.24") From 9ff00240d062ddfa7a26d0752381fedda09cb2de Mon Sep 17 00:00:00 2001 From: dhaus67 Date: Mon, 25 Nov 2024 01:49:47 +0100 Subject: [PATCH 07/12] fix: error types and introduce error types (#143) --- embedded_postgres.go | 13 +++++++++---- embedded_postgres_test.go | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/embedded_postgres.go b/embedded_postgres.go index fcf98d1..87bb427 100644 --- a/embedded_postgres.go +++ b/embedded_postgres.go @@ -14,6 +14,11 @@ import ( var mu sync.Mutex +var ( + ErrServerNotStarted = errors.New("server has not been started") + ErrServerAlreadyStarted = errors.New("server is already started") +) + // EmbeddedPostgres maintains all configuration and runtime functions for maintaining the lifecycle of one Postgres process. type EmbeddedPostgres struct { config Config @@ -63,7 +68,7 @@ func newDatabaseWithConfig(config Config) *EmbeddedPostgres { //nolint:funlen func (ep *EmbeddedPostgres) Start() error { if ep.started { - return errors.New("server is already started") + return ErrServerAlreadyStarted } if err := ensurePortAvailable(ep.config.port); err != nil { @@ -124,7 +129,7 @@ func (ep *EmbeddedPostgres) Start() error { if !reuseData { if err := ep.createDatabase(ep.config.port, ep.config.username, ep.config.password, ep.config.database); err != nil { if stopErr := stopPostgres(ep); stopErr != nil { - return fmt.Errorf("unable to stop database casused by error %s", err) + return fmt.Errorf("unable to stop database caused by error %s", err) } return err @@ -133,7 +138,7 @@ func (ep *EmbeddedPostgres) Start() error { if err := healthCheckDatabaseOrTimeout(ep.config); err != nil { if stopErr := stopPostgres(ep); stopErr != nil { - return fmt.Errorf("unable to stop database casused by error %s", err) + return fmt.Errorf("unable to stop database caused by error %s", err) } return err @@ -177,7 +182,7 @@ func (ep *EmbeddedPostgres) cleanDataDirectoryAndInit() error { // Stop will try to stop the Postgres process gracefully returning an error when there were any problems. func (ep *EmbeddedPostgres) Stop() error { if !ep.started { - return errors.New("server has not been started") + return ErrServerNotStarted } if err := stopPostgres(ep); err != nil { diff --git a/embedded_postgres_test.go b/embedded_postgres_test.go index a6b4bd2..e7e98b3 100644 --- a/embedded_postgres_test.go +++ b/embedded_postgres_test.go @@ -190,7 +190,7 @@ func Test_ErrorWhenStopCalledBeforeStart(t *testing.T) { err := database.Stop() - assert.EqualError(t, err, "server has not been started") + assert.ErrorIs(t, err, ErrServerNotStarted) } func Test_ErrorWhenStartCalledWhenAlreadyStarted(t *testing.T) { @@ -206,7 +206,7 @@ func Test_ErrorWhenStartCalledWhenAlreadyStarted(t *testing.T) { assert.NoError(t, err) err = database.Start() - assert.EqualError(t, err, "server is already started") + assert.ErrorIs(t, err, ErrServerAlreadyStarted) } func Test_ErrorWhenCannotStartPostgresProcess(t *testing.T) { From 7c0ced30394508c74e955df154e4ee7c7b560b30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=9D=A8=E6=96=87?= Date: Mon, 25 Nov 2024 08:50:44 +0800 Subject: [PATCH 08/12] fix: detect pg_ctl exists instead of bin dir (#144) --- embedded_postgres.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embedded_postgres.go b/embedded_postgres.go index 87bb427..33132df 100644 --- a/embedded_postgres.go +++ b/embedded_postgres.go @@ -152,7 +152,7 @@ func (ep *EmbeddedPostgres) downloadAndExtractBinary(cacheExists bool, cacheLoca mu.Lock() defer mu.Unlock() - _, binDirErr := os.Stat(filepath.Join(ep.config.binariesPath, "bin")) + _, binDirErr := os.Stat(filepath.Join(ep.config.binariesPath, "bin", "pg_ctl")) if os.IsNotExist(binDirErr) { if !cacheExists { if err := ep.remoteFetchStrategy(); err != nil { From f5c275bdc5742cf324a86bd8bfd52655b1600800 Mon Sep 17 00:00:00 2001 From: Hugo Dutka Date: Sun, 8 Dec 2024 04:31:47 +0100 Subject: [PATCH 09/12] fix: StartParameters on Windows (#146) * change string delimiting char based on os * test StartParameters in platform_test * explanatory comment * use double quotes instead of single quotes for parameter values on all platforms --- embedded_postgres.go | 6 ++++-- platform-test/platform_test.go | 24 +++++++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/embedded_postgres.go b/embedded_postgres.go index 33132df..afe8497 100644 --- a/embedded_postgres.go +++ b/embedded_postgres.go @@ -201,8 +201,10 @@ func (ep *EmbeddedPostgres) Stop() error { func encodeOptions(port uint32, parameters map[string]string) string { options := []string{fmt.Sprintf("-p %d", port)} for k, v := range parameters { - // Single-quote parameter values - they may have spaces. - options = append(options, fmt.Sprintf("-c %s='%s'", k, v)) + // Double-quote parameter values - they may have spaces. + // Careful: CMD on Windows uses only double quotes to delimit strings. + // It treats single quotes as regular characters. + options = append(options, fmt.Sprintf("-c %s=\"%s\"", k, v)) } return strings.Join(options, " ") } diff --git a/platform-test/platform_test.go b/platform-test/platform_test.go index 42addc0..ea3a291 100644 --- a/platform-test/platform_test.go +++ b/platform-test/platform_test.go @@ -42,10 +42,14 @@ func Test_AllMajorVersions(t *testing.T) { port := uint32(5555 + testNumber) runtimePath := filepath.Join(tempExtractLocation, string(version)) + maxConnections := 150 database := embeddedpostgres.NewDatabase(embeddedpostgres.DefaultConfig(). Version(version). Port(port). - RuntimePath(runtimePath)) + RuntimePath(runtimePath). + StartParameters(map[string]string{ + "max_connections": fmt.Sprintf("%d", maxConnections), + })) if err := database.Start(); err != nil { shutdownDBAndFail(t, err, database, version) @@ -64,6 +68,24 @@ func Test_AllMajorVersions(t *testing.T) { shutdownDBAndFail(t, err, database, version) } + rows, err = db.Query(`SELECT setting::int max_conn FROM pg_settings WHERE name = 'max_connections';`) + if err != nil { + shutdownDBAndFail(t, err, database, version) + } + if !rows.Next() { + shutdownDBAndFail(t, fmt.Errorf("no rows returned for max_connections"), database, version) + } + var maxConnReturned int + if err := rows.Scan(&maxConnReturned); err != nil { + shutdownDBAndFail(t, err, database, version) + } + if maxConnReturned != maxConnections { + shutdownDBAndFail(t, fmt.Errorf("max_connections is %d, not %d as expected", maxConnReturned, maxConnections), database, version) + } + if err := rows.Close(); err != nil { + shutdownDBAndFail(t, err, database, version) + } + if err := db.Close(); err != nil { shutdownDBAndFail(t, err, database, version) } From 24809fa067810e861262fd804135e30295f7fde8 Mon Sep 17 00:00:00 2001 From: Fergus Strange Date: Sun, 8 Dec 2024 14:48:34 +1100 Subject: [PATCH 10/12] Fix osx builds (#147) * Try upgrading to m2 * Try upgrading to m2 * Upgrades --------- Co-authored-by: ferguss --- .circleci/config.yml | 8 +++--- examples/go.mod | 2 +- examples/go.sum | 10 ++++---- go.mod | 11 +++++---- go.sum | 58 ++++++++++---------------------------------- platform-test/go.mod | 3 ++- platform-test/go.sum | 9 ++++--- 7 files changed, 36 insertions(+), 65 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c83551e..bca766f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,10 +5,10 @@ executors: image: ubuntu-2204:2024.01.2 resource_class: arm.medium working_directory: /home/circleci/go/src/github.com/fergusstrange/embedded-postgres - apple-m1: &macos-executor - resource_class: macos.m1.medium.gen1 + apple-m2: &macos-executor + resource_class: m2pro.medium macos: - xcode: "14.2.0" + xcode: "15.4.0" orbs: go: circleci/go@1.11.0 jobs: @@ -38,4 +38,4 @@ workflows: parameters: executor: - linux-arm64 - - apple-m1 + - apple-m2 diff --git a/examples/go.mod b/examples/go.mod index 63b57fb..6d793e6 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -7,7 +7,7 @@ replace github.com/fergusstrange/embedded-postgres => ../ require ( github.com/fergusstrange/embedded-postgres v0.0.0 github.com/jmoiron/sqlx v1.3.5 - github.com/lib/pq v1.10.4 + github.com/lib/pq v1.10.9 github.com/pressly/goose/v3 v3.0.1 go.uber.org/zap v1.21.0 ) diff --git a/examples/go.sum b/examples/go.sum index cf45c6d..b4fdffb 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -20,8 +20,8 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= -github.com/lib/pq v1.10.4 h1:SO9z7FRPzA03QhHKJrH5BXA6HU1rS4V2nIVrrNC1iYk= -github.com/lib/pq v1.10.4/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= +github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= github.com/mattn/go-sqlite3 v1.14.8 h1:gDp86IdQsN/xWjIEmr9MF6o9mpksUgh0fu+9ByFxzIU= @@ -36,8 +36,8 @@ github.com/pressly/goose/v3 v3.0.1 h1:XdndErg0gNhnWGhQYAurNWw2oYuirQTaAN/Dbw+arU github.com/pressly/goose/v3 v3.0.1/go.mod h1:1L3t2XSf5sGj6OkiCD61z2DJARRWr2sqbJt3JKVnbwo= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo= github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= @@ -45,7 +45,7 @@ github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wK go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= -go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8= @@ -81,5 +81,5 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA= diff --git a/go.mod b/go.mod index f2a74b3..e2890a0 100644 --- a/go.mod +++ b/go.mod @@ -3,14 +3,15 @@ module github.com/fergusstrange/embedded-postgres go 1.18 require ( - github.com/lib/pq v1.10.4 - github.com/stretchr/testify v1.7.0 + github.com/lib/pq v1.10.9 + github.com/stretchr/testify v1.10.0 github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 - go.uber.org/goleak v1.1.12 + go.uber.org/goleak v1.3.0 ) require ( - github.com/davecgh/go-spew v1.1.0 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/kr/text v0.2.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - gopkg.in/yaml.v3 v3.0.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index fa38a0b..f7acdf1 100644 --- a/go.sum +++ b/go.sum @@ -1,52 +1,20 @@ -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/lib/pq v1.10.4 h1:SO9z7FRPzA03QhHKJrH5BXA6HU1rS4V2nIVrrNC1iYk= -github.com/lib/pq v1.10.4/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= +github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo= github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos= -github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA= -go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA= -golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA= -gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/platform-test/go.mod b/platform-test/go.mod index 0565a5f..d8ea4d3 100644 --- a/platform-test/go.mod +++ b/platform-test/go.mod @@ -8,7 +8,8 @@ require github.com/fergusstrange/embedded-postgres v0.0.0 require ( github.com/davecgh/go-spew v1.1.1 // indirect - github.com/lib/pq v1.10.4 // indirect + github.com/lib/pq v1.10.9 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/platform-test/go.sum b/platform-test/go.sum index 52cf44d..3f68aa5 100644 --- a/platform-test/go.sum +++ b/platform-test/go.sum @@ -1,12 +1,13 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/lib/pq v1.10.4 h1:SO9z7FRPzA03QhHKJrH5BXA6HU1rS4V2nIVrrNC1iYk= -github.com/lib/pq v1.10.4/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= +github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo= github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos= -go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 6192f2a75d261b76166d852e0e763f57d14e47fa Mon Sep 17 00:00:00 2001 From: ferguss Date: Sun, 8 Dec 2024 14:53:29 +1100 Subject: [PATCH 11/12] Clean up go mod files --- examples/go.sum | 2 +- platform-test/go.mod | 3 --- platform-test/go.sum | 4 ---- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/examples/go.sum b/examples/go.sum index b4fdffb..ebbe500 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -81,5 +81,5 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/platform-test/go.mod b/platform-test/go.mod index d8ea4d3..015a70e 100644 --- a/platform-test/go.mod +++ b/platform-test/go.mod @@ -7,9 +7,6 @@ go 1.18 require github.com/fergusstrange/embedded-postgres v0.0.0 require ( - github.com/davecgh/go-spew v1.1.1 // indirect github.com/lib/pq v1.10.9 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/platform-test/go.sum b/platform-test/go.sum index 3f68aa5..15b36a7 100644 --- a/platform-test/go.sum +++ b/platform-test/go.sum @@ -1,13 +1,9 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo= github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 4fb7ddc646853d24521dfbb119c9a3fbf6f8a675 Mon Sep 17 00:00:00 2001 From: Danny Kopping Date: Mon, 2 Jun 2025 12:36:58 +0200 Subject: [PATCH 12/12] fix: prevent panic when `*http.Response` is nil (#156) * fix: prevent panic when *http.Response is nil Signed-off-by: Danny Kopping * fix: add error handling for sha256 download Signed-off-by: Danny Kopping * fix: check body nilness as well Signed-off-by: Danny Kopping --------- Signed-off-by: Danny Kopping --- remote_fetch.go | 7 ++++++- remote_fetch_test.go | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/remote_fetch.go b/remote_fetch.go index 1aa1e84..bc95756 100644 --- a/remote_fetch.go +++ b/remote_fetch.go @@ -50,7 +50,9 @@ func defaultRemoteFetchStrategy(remoteFetchHost string, versionStrategy VersionS shaDownloadURL := fmt.Sprintf("%s.sha256", jarDownloadURL) shaDownloadResponse, err := http.Get(shaDownloadURL) - + if err != nil { + return fmt.Errorf("download sha256 from %s failed: %w", shaDownloadURL, err) + } defer closeBody(shaDownloadResponse)() if err == nil && shaDownloadResponse.StatusCode == http.StatusOK { @@ -68,6 +70,9 @@ func defaultRemoteFetchStrategy(remoteFetchHost string, versionStrategy VersionS func closeBody(resp *http.Response) func() { return func() { + if resp == nil || resp.Body == nil { + return + } if err := resp.Body.Close(); err != nil { log.Fatal(err) } diff --git a/remote_fetch_test.go b/remote_fetch_test.go index 9e6dcfb..2b4a76b 100644 --- a/remote_fetch_test.go +++ b/remote_fetch_test.go @@ -417,3 +417,9 @@ func Test_defaultRemoteFetchStrategy_whenContentLengthNotSet(t *testing.T) { assert.NoError(t, err) assert.FileExists(t, cacheLocation) } + +func Test_closeBody_NilResponse(t *testing.T) { + assert.NotPanics(t, func() { + closeBody(nil)() + }) +}