Skip to content

Commit 44a7d67

Browse files
committed
add test for show non default port
1 parent 59506cb commit 44a7d67

File tree

3 files changed

+86
-21
lines changed

3 files changed

+86
-21
lines changed

testing/go/framework.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ func RunScript(t *testing.T, script ScriptTest, normalizeRows bool) {
164164
controller.Stop()
165165
err := controller.WaitForStop()
166166
require.NoError(t, err)
167-
currentPort = 5432
168167
}()
169168
}
170169

@@ -339,9 +338,15 @@ func init() {
339338
// when the connection is closed (or loses its connection to the server). The accompanying WaitGroup may be used to wait
340339
// until the server has closed.
341340
func CreateServer(t *testing.T, database string) (context.Context, *Connection, *svcs.Controller) {
342-
require.NotEmpty(t, database)
343341
port := GetUnusedPort(t)
344-
currentPort = port
342+
return CreateServerWithPort(t, database, port)
343+
}
344+
345+
// CreateServerWithPort creates a server with the given database and port, returning a connection to the server. The server will close
346+
// when the connection is closed (or loses its connection to the server). The accompanying WaitGroup may be used to wait
347+
// until the server has closed.
348+
func CreateServerWithPort(t *testing.T, database string, port int) (context.Context, *Connection, *svcs.Controller) {
349+
require.NotEmpty(t, database)
345350
controller, err := dserver.RunInMemory(&servercfg.DoltgresConfig{
346351
ListenerConfig: &servercfg.DoltgresListenerConfig{
347352
PortNumber: &port,
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright 2025 Dolthub, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package _go
16+
17+
import (
18+
"context"
19+
"fmt"
20+
"github.com/dolthub/dolt/go/libraries/utils/svcs"
21+
"github.com/stretchr/testify/require"
22+
"testing"
23+
24+
"github.com/jackc/pgx/v5"
25+
26+
"github.com/dolthub/go-mysql-server/sql"
27+
)
28+
29+
func TestServerConfigVariableStatement(t *testing.T) {
30+
scriptDatabase := "postgres"
31+
var ctx context.Context
32+
var conn *Connection
33+
port := GetUnusedPort(t)
34+
35+
if runOnPostgres {
36+
ctx = context.Background()
37+
pgxConn, err := pgx.Connect(ctx, fmt.Sprintf("postgres://postgres:[email protected]:%d/%s?sslmode=disable", 5432, scriptDatabase))
38+
require.NoError(t, err)
39+
conn = &Connection{
40+
Default: pgxConn,
41+
Current: pgxConn,
42+
}
43+
require.NoError(t, pgxConn.Ping(ctx))
44+
defer func() {
45+
conn.Close(ctx)
46+
}()
47+
} else {
48+
var controller *svcs.Controller
49+
ctx, conn, controller = CreateServerWithPort(t, scriptDatabase, port)
50+
defer func() {
51+
conn.Close(ctx)
52+
controller.Stop()
53+
err := controller.WaitForStop()
54+
require.NoError(t, err)
55+
}()
56+
}
57+
58+
t.Run("show 'port' configuration variable", func(t *testing.T) {
59+
runScript(t, ctx, ScriptTest{
60+
Name: "set 'port' configuration variable",
61+
SetUpScript: []string{},
62+
Assertions: []ScriptTestAssertion{
63+
{
64+
Query: "SHOW port",
65+
Expected: []sql.Row{{port}},
66+
},
67+
{
68+
Query: "SET port TO '5432'",
69+
ExpectedErr: "is a read only variable",
70+
},
71+
{
72+
Query: "SELECT current_setting('port')",
73+
Expected: []sql.Row{{fmt.Sprintf("%v", port)}},
74+
},
75+
},
76+
}, conn, true)
77+
})
78+
}

testing/go/set_test.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5836,24 +5836,6 @@ var setStmts = []ScriptTest{
58365836
},
58375837
},
58385838
},
5839-
{
5840-
Name: "set 'port' configuration variable",
5841-
SetUpScript: []string{},
5842-
Assertions: []ScriptTestAssertion{
5843-
{
5844-
Query: "SHOW port",
5845-
Expected: []sql.Row{{currentPort}},
5846-
},
5847-
{
5848-
Query: "SET port TO '5432'",
5849-
ExpectedErr: "is a read only variable",
5850-
},
5851-
{
5852-
Query: "SELECT current_setting('port')",
5853-
Expected: []sql.Row{{fmt.Sprintf("%v", currentPort)}},
5854-
},
5855-
},
5856-
},
58575839
{
58585840
Name: "set 'post_auth_delay' configuration variable",
58595841
SetUpScript: []string{},

0 commit comments

Comments
 (0)