aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/ClickHouse/ch-go/proto/client_info_test.go
blob: 6ccf2def54f8fa71881e5c89f93079e8a935fb70 (plain) (blame)
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
package proto

import (
	"bytes"
	"testing"

	"github.com/stretchr/testify/assert"
	"go.opentelemetry.io/otel/trace"

	"github.com/ClickHouse/ch-go/internal/gold"
)

func TestClientInfo_EncodeAware(t *testing.T) {
	b := new(Buffer)
	v := queryCreateDatabase.Info
	v.EncodeAware(b, queryProtoVersion)
	gold.Bytes(t, b.Buf, "client_info")

	t.Run("DecodeAware", func(t *testing.T) {
		var i ClientInfo
		r := NewReader(bytes.NewReader(b.Buf))
		assert.NoError(t, i.DecodeAware(r, queryProtoVersion))
		assert.Equal(t, v, i)

		requireNoShortRead(t, b.Buf, aware(&i))
	})
}

func TestClientInfo_OpenTelemetry(t *testing.T) {
	b := new(Buffer)
	v := ClientInfo{
		ProtocolVersion: 54429,
		Major:           21,
		Minor:           11,
		Patch:           4,
		Interface:       InterfaceTCP,
		Query:           ClientQueryInitial,

		InitialUser:    "",
		InitialQueryID: "40c268ad-de50-434d-a391-800da9aa70c3",
		InitialAddress: "0.0.0.0:0",
		OSUser:         "user",
		ClientHostname: "hostname",
		ClientName:     "Name",
		Span: trace.NewSpanContext(trace.SpanContextConfig{
			TraceID: trace.TraceID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
			SpanID:  trace.SpanID{1, 2, 3, 4, 5, 6, 7, 8},
		}),
		QuotaKey:         "",
		DistributedDepth: 0,
	}
	v.EncodeAware(b, Version)
	gold.Bytes(t, b.Buf, "client_info_otel")

	t.Run("DecodeAware", func(t *testing.T) {
		var i ClientInfo
		r := NewReader(bytes.NewReader(b.Buf))
		assert.NoError(t, i.DecodeAware(r, Version))
		assert.Equal(t, v, i)
		requireNoShortRead(t, b.Buf, aware(&i))
	})
}