Skip to content

Commit

Permalink
add more test
Browse files Browse the repository at this point in the history
Signed-off-by: zzzk1 <[email protected]>
  • Loading branch information
zzzk1 committed Feb 15, 2025
1 parent 7e9f49c commit 9570553
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 20 deletions.
8 changes: 6 additions & 2 deletions internal/storage/v2/clickhouse/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

"github.com/ClickHouse/ch-go/cht"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"

Expand All @@ -27,8 +28,9 @@ func TestClickHouseFactoryWithConfig(t *testing.T) {
cht.New(t,
cht.WithLog(zap.NewNop()),
)
_, err := NewFactoryWithConfig(&cfg, zap.NewNop())
f, err := NewFactoryWithConfig(&cfg, zap.NewNop())
require.NoError(t, err)
defer f.Close()
}

func TestCreateTraceWriter(t *testing.T) {
Expand All @@ -40,6 +42,8 @@ func TestCreateTraceWriter(t *testing.T) {

f, err := NewFactoryWithConfig(&cfg, zap.NewNop())
require.NoError(t, err)
_, err = f.CreateTraceWriter()
traceWriter, err := f.CreateTraceWriter()
require.NoError(t, err)
assert.NotEmpty(t, traceWriter)
defer f.Close()
}
14 changes: 0 additions & 14 deletions internal/storage/v2/clickhouse/package_test.go

This file was deleted.

6 changes: 6 additions & 0 deletions pkg/clickhouse/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ func (c *Configuration) newPool(log *zap.Logger) (*chpool.Pool, error) {
HealthCheckPeriod: c.ConnectionPoolConfig.HealthCheckPeriod,
}
chPool, err := chpool.Dial(context.Background(), option)
if err != nil {
return nil, err
}
return chPool, err
}

Expand All @@ -112,5 +115,8 @@ func (c *Configuration) newConn() (driver.Conn, error) {
},
}
conn, err := clientV2.Open(&option)
if err != nil {
return nil, err
}
return conn, err
}
41 changes: 37 additions & 4 deletions pkg/clickhouse/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/pkg/testutils"
)

func TestDefaultConfig(t *testing.T) {
Expand All @@ -35,6 +33,41 @@ func TestNewClientWithDefaults(t *testing.T) {
defer client.Close()
}

func TestMain(m *testing.M) {
testutils.VerifyGoLeaks(m)
func TestNewPool(t *testing.T) {
cfg := DefaultConfiguration()
logger := zap.NewNop()
conn, err := cfg.newConn()

cht.New(t,
cht.WithLog(logger),
)

require.NoError(t, err)
assert.NotEmpty(t, conn)
defer conn.Close()
}

func TestNewPoolFail(t *testing.T) {
cfg := Configuration{}
logger := zap.NewNop()
pool, err := cfg.newPool(logger)

cht.New(t,
cht.WithLog(logger),
)

require.Error(t, err)
assert.Nil(t, pool)
}

func TestNewConnection(t *testing.T) {
cfg := DefaultConfiguration()
logger := zap.NewNop()

cht.New(t, cht.WithLog(logger))

conn, err := cfg.newConn()
require.NoError(t, err)
assert.NotEmpty(t, conn)
defer conn.Close()
}

0 comments on commit 9570553

Please sign in to comment.