@@ -29,6 +29,7 @@ import (
29
29
"errors"
30
30
"fmt"
31
31
"net/http"
32
+ "os"
32
33
"testing"
33
34
"time"
34
35
@@ -91,6 +92,35 @@ func TestHttpHappyCasesFromConf(t *testing.T) {
91
92
}
92
93
}
93
94
95
+ func TestHttpHappyCasesFromEnv (t * testing.T ) {
96
+ var (
97
+ addr = "localhost:1111"
98
+ )
99
+
100
+ testCases := []httpConfigTestCase {
101
+ {
102
+ name : "addr only" ,
103
+ config : fmt .Sprintf ("http::addr=%s" , addr ),
104
+ },
105
+ {
106
+ name : "auto flush" ,
107
+ config : fmt .Sprintf ("http::addr=%s;auto_flush_rows=100;auto_flush_interval=1000;" ,
108
+ addr ),
109
+ },
110
+ }
111
+
112
+ for _ , tc := range testCases {
113
+ t .Run (tc .name , func (t * testing.T ) {
114
+ os .Setenv ("QDB_CLIENT_CONF" , tc .config )
115
+ sender , err := qdb .LineSenderFromEnv (context .Background ())
116
+ assert .NoError (t , err )
117
+
118
+ sender .Close (context .Background ())
119
+ os .Unsetenv ("QDB_CLIENT_CONF" )
120
+ })
121
+ }
122
+ }
123
+
94
124
func TestHttpPathologicalCasesFromConf (t * testing.T ) {
95
125
testCases := []httpConfigTestCase {
96
126
{
@@ -148,6 +178,42 @@ func TestHttpPathologicalCasesFromConf(t *testing.T) {
148
178
}
149
179
}
150
180
181
+ func TestHttpPathologicalCasesFromEnv (t * testing.T ) {
182
+ // Test a few cases just to make sure that the config is read
183
+ // from the env variable.
184
+ testCases := []httpConfigTestCase {
185
+ {
186
+ name : "basic_and_token_auth" ,
187
+ config : "http::username=test_user;token=test_token;" ,
188
+ expectedErr : "both basic and token" ,
189
+ },
190
+ {
191
+ name : "negative max_buf_size" ,
192
+ config : "http::max_buf_size=-1;" ,
193
+ expectedErr : "max buffer size is negative" ,
194
+ },
195
+ {
196
+ name : "schema is case-sensitive" ,
197
+ config : "hTtp::addr=localhost:1234;" ,
198
+ expectedErr : "invalid schema" ,
199
+ },
200
+ }
201
+
202
+ for _ , tc := range testCases {
203
+ t .Run (tc .name , func (t * testing.T ) {
204
+ os .Setenv ("QDB_CLIENT_CONF" , tc .config )
205
+ _ , err := qdb .LineSenderFromEnv (context .Background ())
206
+ assert .ErrorContains (t , err , tc .expectedErr )
207
+ os .Unsetenv ("QDB_CLIENT_CONF" )
208
+ })
209
+ }
210
+ }
211
+
212
+ func TestHttpEmptyEnvVariableCaseFromEnv (t * testing.T ) {
213
+ _ , err := qdb .LineSenderFromEnv (context .Background ())
214
+ assert .ErrorContains (t , err , "QDB_CLIENT_CONF environment variable is not set" )
215
+ }
216
+
151
217
func TestErrorWhenSenderTypeIsNotSpecified (t * testing.T ) {
152
218
ctx := context .Background ()
153
219
0 commit comments