Skip to content

Commit 2764d1d

Browse files
committed
platform test: test PG_VERSION file to match requested version
1 parent 6fac96c commit 2764d1d

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

platform-test/platform_test.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import (
77
"os"
88
"path/filepath"
99
"strconv"
10+
"strings"
1011
"testing"
1112

12-
"github.com/fergusstrange/embedded-postgres"
13+
embeddedpostgres "github.com/fergusstrange/embedded-postgres"
1314
)
1415

1516
func Test_AllMajorVersions(t *testing.T) {
@@ -28,10 +29,11 @@ func Test_AllMajorVersions(t *testing.T) {
2829
for testNumber, version := range allVersions {
2930
t.Run(fmt.Sprintf("MajorVersion_%d", testNumber), func(t *testing.T) {
3031
port := uint32(5555 + testNumber)
32+
runtimePath := filepath.Join(tempExtractLocation, strconv.Itoa(testNumber))
3133
database := embeddedpostgres.NewDatabase(embeddedpostgres.DefaultConfig().
3234
Version(version).
3335
Port(port).
34-
RuntimePath(filepath.Join(tempExtractLocation, strconv.Itoa(testNumber))))
36+
RuntimePath(runtimePath))
3537

3638
if err := database.Start(); err != nil {
3739
shutdownDBAndFail(t, err, database, version)
@@ -57,6 +59,10 @@ func Test_AllMajorVersions(t *testing.T) {
5759
if err := database.Stop(); err != nil {
5860
t.Fatal(err)
5961
}
62+
63+
if err := checkPgVersionFile(filepath.Join(runtimePath, "data"), version); err != nil {
64+
t.Fatal(err)
65+
}
6066
})
6167
}
6268
if err := os.RemoveAll(tempExtractLocation); err != nil {
@@ -75,3 +81,20 @@ func connect(port uint32) (*sql.DB, error) {
7581
db, err := sql.Open("postgres", fmt.Sprintf("host=localhost port=%d user=postgres password=postgres dbname=postgres sslmode=disable", port))
7682
return db, err
7783
}
84+
85+
func checkPgVersionFile(dataDir string, version embeddedpostgres.PostgresVersion) error {
86+
pgVersion := filepath.Join(dataDir, "PG_VERSION")
87+
88+
d, err := ioutil.ReadFile(pgVersion)
89+
if err != nil {
90+
return fmt.Errorf("could not read file %v", pgVersion)
91+
}
92+
93+
v := strings.TrimSuffix(string(d), "\n")
94+
95+
if strings.HasPrefix(string(version), v) {
96+
return nil
97+
}
98+
99+
return fmt.Errorf("version missmatch in PG_VERSION: %v <> %v", string(version), v)
100+
}

0 commit comments

Comments
 (0)