@@ -31,6 +31,8 @@ import (
3131 "time"
3232
3333 "github.com/ClickHouse/clickhouse-go/v2"
34+ "github.com/ClickHouse/clickhouse-go/v2/lib/driver"
35+ "github.com/ClickHouse/clickhouse-go/v2/lib/proto"
3436 clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests"
3537 "github.com/stretchr/testify/assert"
3638 "github.com/stretchr/testify/require"
@@ -231,6 +233,80 @@ func TestStdConnector(t *testing.T) {
231233 require .NoError (t , err )
232234}
233235
236+ func TestCustomProtocolRevision (t * testing.T ) {
237+ env , err := GetStdTestEnvironment ()
238+ require .NoError (t , err )
239+ useSSL , err := strconv .ParseBool (clickhouse_tests .GetEnv ("CLICKHOUSE_USE_SSL" , "false" ))
240+ require .NoError (t , err )
241+ port := env .Port
242+ var tlsConfig * tls.Config
243+ if useSSL {
244+ port = env .SslPort
245+ tlsConfig = & tls.Config {}
246+ }
247+ baseOpts := clickhouse.Options {
248+ Addr : []string {fmt .Sprintf ("%s:%d" , env .Host , port )},
249+ Auth : clickhouse.Auth {
250+ Database : "default" ,
251+ Username : env .Username ,
252+ Password : env .Password ,
253+ },
254+ Compression : & clickhouse.Compression {
255+ Method : clickhouse .CompressionLZ4 ,
256+ },
257+ TLS : tlsConfig ,
258+ }
259+ t .Run ("unsupported proto versions" , func (t * testing.T ) {
260+ badOpts := baseOpts
261+ badOpts .ProtocolRevision = proto .DBMS_MIN_REVISION_WITH_CLIENT_INFO - 1
262+ conn , _ := clickhouse .Open (& badOpts )
263+ require .NotNil (t , conn )
264+ err = conn .Ping (t .Context ())
265+ require .Error (t , err )
266+ badOpts .ProtocolRevision = proto .DBMS_TCP_PROTOCOL_VERSION + 1
267+ conn , _ = clickhouse .Open (& badOpts )
268+ require .NotNil (t , conn )
269+ err = conn .Ping (t .Context ())
270+ require .Error (t , err )
271+ })
272+
273+ t .Run ("minimal proto version" , func (t * testing.T ) {
274+ opts := baseOpts
275+ opts .ProtocolRevision = proto .DBMS_MIN_REVISION_WITH_CLIENT_INFO
276+ conn , err := clickhouse .Open (& opts )
277+ require .NoError (t , err )
278+ require .NotNil (t , conn )
279+ err = conn .Ping (t .Context ())
280+ require .NoError (t , err )
281+
282+ defer func () {
283+ _ = conn .Exec (t .Context (), "DROP TABLE insert_example" )
284+ }()
285+ err = conn .Exec (t .Context (), "DROP TABLE IF EXISTS insert_example" )
286+
287+ err = conn .Exec (t .Context (), `
288+ CREATE TABLE insert_example (
289+ Col1 UInt64
290+ ) Engine = MergeTree() ORDER BY tuple()
291+ ` )
292+ require .NoError (t , err )
293+ var batch driver.Batch
294+ batch , err = conn .PrepareBatch (t .Context (), "INSERT INTO insert_example (Col1)" )
295+ require .NoError (t , err )
296+ require .NoError (t , batch .Append (10 ))
297+ require .NoError (t , batch .Send ())
298+
299+ rows , err := conn .Query (t .Context (), "SELECT Col1 FROM insert_example" )
300+ require .NoError (t , err )
301+ count := 0
302+ for rows .Next () {
303+ count ++
304+ }
305+ assert .Equal (t , 1 , count )
306+ })
307+
308+ }
309+
234310func TestBlockBufferSize (t * testing.T ) {
235311 env , err := GetStdTestEnvironment ()
236312 require .NoError (t , err )
0 commit comments