-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathhttp_integration_test.go
124 lines (104 loc) · 3.43 KB
/
http_integration_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
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
/*******************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (c) 2014-2019 Appsicle
* Copyright (c) 2019-2022 QuestDB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
package questdb_test
import (
"context"
"reflect"
"testing"
"time"
qdb "github.com/questdb/go-questdb-client/v3"
"github.com/stretchr/testify/assert"
)
func (suite *integrationTestSuite) TestE2ESuccessfulHttpBasicAuthWithTlsProxy() {
if testing.Short() {
suite.T().Skip("skipping integration test")
}
ctx := context.Background()
questdbC, err := setupQuestDB(ctx, httpBasicAuth)
assert.NoError(suite.T(), err)
defer questdbC.Stop(ctx)
sender, err := qdb.NewLineSender(
ctx,
qdb.WithHttp(),
qdb.WithAddress(questdbC.proxyIlpHttpAddress),
qdb.WithBasicAuth(basicAuthUser, basicAuthPass),
qdb.WithTlsInsecureSkipVerify(),
)
assert.NoError(suite.T(), err)
defer sender.Close(ctx)
err = sender.
Table(testTable).
StringColumn("str_col", "foobar").
At(ctx, time.UnixMicro(1))
assert.NoError(suite.T(), err)
err = sender.
Table(testTable).
StringColumn("str_col", "barbaz").
At(ctx, time.UnixMicro(2))
assert.NoError(suite.T(), err)
err = sender.Flush(ctx)
assert.NoError(suite.T(), err)
expected := tableData{
Columns: []column{
{"str_col", "STRING"},
{"timestamp", "TIMESTAMP"},
},
Dataset: [][]interface{}{
{"foobar", "1970-01-01T00:00:00.000001Z"},
{"barbaz", "1970-01-01T00:00:00.000002Z"},
},
Count: 2,
}
assert.Eventually(suite.T(), func() bool {
data := queryTableData(suite.T(), testTable, questdbC.httpAddress)
return reflect.DeepEqual(expected, data)
}, eventualDataTimeout, 100*time.Millisecond)
}
func (suite *integrationTestSuite) TestServerSideError() {
if testing.Short() {
suite.T().Skip("skipping integration test")
}
ctx := context.Background()
var (
sender qdb.LineSender
err error
)
questdbC, err := setupQuestDB(ctx, noAuth)
assert.NoError(suite.T(), err)
sender, err = qdb.NewLineSender(ctx, qdb.WithHttp(), qdb.WithAddress(questdbC.httpAddress))
assert.NoError(suite.T(), err)
err = sender.Table(testTable).Int64Column("long_col", 42).AtNow(ctx)
assert.NoError(suite.T(), err)
err = sender.Flush(ctx)
assert.NoError(suite.T(), err)
// Now, use wrong type for the long_col.
err = sender.Table(testTable).StringColumn("long_col", "42").AtNow(ctx)
assert.NoError(suite.T(), err)
err = sender.Flush(ctx)
assert.Error(suite.T(), err)
assert.ErrorContains(suite.T(), err, "my_test_table, column: long_col; cast error from protocol type: STRING to column type")
assert.ErrorContains(suite.T(), err, "line: 1")
sender.Close(ctx)
questdbC.Stop(ctx)
}