-
Notifications
You must be signed in to change notification settings - Fork 3
/
startup_test.go
52 lines (44 loc) · 1.43 KB
/
startup_test.go
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
package pgvertica
import (
"context"
"testing"
"github.com/jackc/pgproto3/v2"
"github.com/stretchr/testify/assert"
)
func TestServeConnStartup_HandleStartupMessage_Success(t *testing.T) {
ctx := context.Background()
config := ServerConfig{
PostgresConnectionString: "postgres://test:test@localhost:5432/test?sslmode=disable",
VerticaConnectionString: "vertica://test:test@localhost:5433/test?sslmode=disable",
}
c := Conn{
Conn: &MockConn{},
}
mockReceiver := new(MockReceiver)
mockReceiver.On("ReceiveStartupMessage").Return(&pgproto3.StartupMessage{
ProtocolVersion: pgproto3.ProtocolVersionNumber,
Parameters: map[string]string{"database": "test"},
}, nil)
c.receiver = mockReceiver
_, err := serveConnStartup(ctx, &c, &config)
assert.NoError(t, err)
}
func TestHandleStartupMessage_Success(t *testing.T) {
ctx := context.Background()
config := ServerConfig{
PostgresConnectionString: "postgres://test:test@localhost:5432/test?sslmode=disable",
VerticaConnectionString: "vertica://test:test@localhost:5433/test?sslmode=disable",
}
c := Conn{
Conn: &MockConn{},
}
mockReceiver := new(MockReceiver)
msg := &pgproto3.StartupMessage{
ProtocolVersion: pgproto3.ProtocolVersionNumber,
Parameters: map[string]string{"database": "test"},
}
mockReceiver.On("ReceiveStartupMessage").Return(msg, nil)
c.receiver = mockReceiver
err := handleStartupMessage(ctx, &c, msg, &config)
assert.NoError(t, err)
}