-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathminor_version_upgrade_test.go
More file actions
129 lines (103 loc) · 3.1 KB
/
minor_version_upgrade_test.go
File metadata and controls
129 lines (103 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//go:build e2e_test
package e2e
import (
"context"
"testing"
"time"
"github.com/jackc/pgx/v5"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
controlplane "github.com/pgEdge/control-plane/api/apiv1/gen/control_plane"
)
func TestMinorVersionUpgrade(t *testing.T) {
t.Parallel()
host1 := fixture.HostIDs()[0]
host2 := fixture.HostIDs()[1]
username := "admin"
password := "password"
fromVersion := "18.2"
toVersion := "18.3"
ctx, cancel := context.WithTimeout(t.Context(), 5*time.Minute)
defer cancel()
t.Logf("creating database with initial version %s", fromVersion)
db := fixture.NewDatabaseFixture(t.Context(), t, &controlplane.CreateDatabaseRequest{
Spec: &controlplane.DatabaseSpec{
DatabaseName: "test",
PostgresVersion: &fromVersion,
Port: pointerTo(0),
DatabaseUsers: []*controlplane.DatabaseUserSpec{
{
Username: username,
Password: pointerTo(password),
DbOwner: pointerTo(true),
Attributes: []string{"LOGIN", "SUPERUSER"},
},
},
Nodes: []*controlplane.DatabaseNodeSpec{
{
Name: "n1", HostIds: []controlplane.Identifier{
controlplane.Identifier(host1),
controlplane.Identifier(host2),
},
},
},
},
})
t.Log("asserting that the primary is running on the first host")
// Assert that the primary is running on the first host in the host_ids
// list.
primary := db.GetInstance(WithRole("primary"))
require.NotNil(t, primary)
assert.Equal(t, host1, primary.HostID)
opts := ConnectionOptions{
InstanceID: primary.ID,
Username: username,
Password: password,
}
t.Logf("validating that the initial version is %s", fromVersion)
db.WithConnection(ctx, opts, t, func(conn *pgx.Conn) {
var current string
rows := conn.QueryRow(ctx, "SHOW server_version;")
require.NoError(t, rows.Scan(¤t))
assert.Equal(t, fromVersion, current)
})
t.Logf("updating version to %s", toVersion)
// Bump the minor version
err := db.Update(ctx, UpdateOptions{
Spec: &controlplane.DatabaseSpec{
DatabaseName: "test",
PostgresVersion: &toVersion,
Port: pointerTo(0),
DatabaseUsers: []*controlplane.DatabaseUserSpec{
{
Username: username,
Password: pointerTo(password),
DbOwner: pointerTo(true),
Attributes: []string{"LOGIN", "SUPERUSER"},
},
},
Nodes: []*controlplane.DatabaseNodeSpec{
{
Name: "n1", HostIds: []controlplane.Identifier{
controlplane.Identifier(host1),
controlplane.Identifier(host2),
},
},
},
},
})
require.NoError(t, err)
t.Log("asserting that the primary hasn't changed")
// Assert that the primary hasn't changed
updated := db.GetInstance(WithRole("primary"))
require.NotNil(t, updated)
assert.Equal(t, primary.ID, updated.ID)
assert.Equal(t, primary.HostID, updated.HostID)
t.Logf("validating that the version is updated to %s", toVersion)
db.WithConnection(ctx, opts, t, func(conn *pgx.Conn) {
var current string
rows := conn.QueryRow(ctx, "SHOW server_version;")
require.NoError(t, rows.Scan(¤t))
assert.Equal(t, toVersion, current)
})
}