Skip to content

Commit

Permalink
Improve docs and add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
puzpuzpuz committed Mar 20, 2024
1 parent 40f560a commit d261f2e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
35 changes: 35 additions & 0 deletions http_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,38 @@ func (suite *integrationTestSuite) TestE2ESuccessfulHttpBasicAuthWithTlsProxy()
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)
}
8 changes: 8 additions & 0 deletions http_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ func TestHttpPathologicalCasesFromConf(t *testing.T) {
}
}

func TestErrorWhenSenderTypeIsNotSpecified(t *testing.T) {
ctx := context.Background()

_, err := qdb.NewLineSender(ctx)
assert.Error(t, err)
assert.ErrorContains(t, err, "sender type is not specified: use WithHttp or WithTcp")
}

func TestHttpErrorWhenMaxBufferSizeIsReached(t *testing.T) {
ctx := context.Background()

Expand Down
5 changes: 2 additions & 3 deletions sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func WithAutoFlushInterval(interval time.Duration) LineSenderOption {
// http(s) and tcp(s):
// -------------------
// addr: hostname/port of QuestDB endpoint
// init_buf_size: initial growable ILP buffer size in bytes (defaults to 64KiB)
// init_buf_size: initial growable ILP buffer size in bytes (defaults to 128KiB)
// tls_verify: determines if TLS certificates should be validated (defaults to "on", can be set to "unsafe_off")
//
// http(s)-only
Expand All @@ -420,13 +420,12 @@ func WithAutoFlushInterval(interval time.Duration) LineSenderOption {
// request_min_throughput: bytes per second, used to calculate each request's timeout (defaults to 100KiB/s)
// request_timeout: minimum request timeout in milliseconds (defaults to 10 seconds)
// retry_timeout: cumulative maximum millisecond duration spent in retries (defaults to 10 seconds)
// max_buf_size: buffer growth limit in bytes. client errors if breached (default is 100MiB)
// max_buf_size: buffer growth limit in bytes. Client errors if breached (default is 100MiB)
//
// tcp(s)-only
// -----------
// username: KID (key ID) for ECDSA authentication
// token: Secret K (D) for ECDSA authentication

func LineSenderFromConf(ctx context.Context, conf string) (LineSender, error) {
c, err := confFromStr(conf)
if err != nil {
Expand Down

0 comments on commit d261f2e

Please sign in to comment.