mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
cmd: take configuration as a mandatory argument (+ other changes)
The other changes are: - rename configure service to orchestrator service - turn DefaultConfiguration variables into functions
This commit is contained in:
97
orchestrator/clickhouse/functional_test.go
Normal file
97
orchestrator/clickhouse/functional_test.go
Normal file
@@ -0,0 +1,97 @@
|
||||
package clickhouse
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/ClickHouse/clickhouse-go/v2"
|
||||
|
||||
"akvorado/common/daemon"
|
||||
"akvorado/common/helpers"
|
||||
"akvorado/common/http"
|
||||
"akvorado/common/reporter"
|
||||
)
|
||||
|
||||
func TestRealClickHouse(t *testing.T) {
|
||||
chServer := helpers.CheckExternalService(t, "ClickHouse", []string{"clickhouse", "localhost"}, "9000")
|
||||
|
||||
configuration := DefaultConfiguration()
|
||||
configuration.Servers = []string{chServer}
|
||||
r := reporter.NewMock(t)
|
||||
ch, err := New(r, configuration, Dependencies{
|
||||
Daemon: daemon.NewMock(t),
|
||||
HTTP: http.NewMock(t, r),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("New() error:\n%+v", err)
|
||||
}
|
||||
if err := ch.Start(); err != nil {
|
||||
t.Fatalf("Start() error:\n%+v", err)
|
||||
}
|
||||
select {
|
||||
case <-ch.migrationsDone:
|
||||
case <-time.After(3 * time.Second):
|
||||
t.Fatalf("Migrations not done")
|
||||
}
|
||||
|
||||
// Check with the ClickHouse client we have our tables
|
||||
conn := clickhouse.OpenDB(&clickhouse.Options{
|
||||
Addr: []string{chServer},
|
||||
Auth: clickhouse.Auth{
|
||||
Database: ch.config.Database,
|
||||
Username: ch.config.Username,
|
||||
Password: ch.config.Password,
|
||||
},
|
||||
DialTimeout: 100 * time.Millisecond,
|
||||
})
|
||||
if err := conn.Ping(); err != nil {
|
||||
t.Fatalf("Ping() error:\n%+v", err)
|
||||
}
|
||||
rows, err := conn.Query("SHOW TABLES")
|
||||
if err != nil {
|
||||
t.Fatalf("Query() error:\n%+v", err)
|
||||
}
|
||||
got := []string{}
|
||||
for rows.Next() {
|
||||
var table string
|
||||
if err := rows.Scan(&table); err != nil {
|
||||
t.Fatalf("Scan() error:\n%+v", err)
|
||||
}
|
||||
if !strings.HasPrefix(table, ".") {
|
||||
got = append(got, table)
|
||||
}
|
||||
}
|
||||
expected := []string{
|
||||
"asns",
|
||||
"exporters",
|
||||
"flows",
|
||||
"flows_1_raw",
|
||||
"flows_1_raw_consumer",
|
||||
"protocols",
|
||||
}
|
||||
if diff := helpers.Diff(got, expected); diff != "" {
|
||||
t.Fatalf("SHOW TABLES (-got, +want):\n%s", diff)
|
||||
}
|
||||
if err := ch.Stop(); err != nil {
|
||||
t.Fatalf("Stop() error:\n%+v", err)
|
||||
}
|
||||
|
||||
// Check we can run a second time
|
||||
ch, err = New(r, configuration, Dependencies{
|
||||
Daemon: daemon.NewMock(t),
|
||||
HTTP: http.NewMock(t, r),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("New() error:\n%+v", err)
|
||||
}
|
||||
if err := ch.Start(); err != nil {
|
||||
t.Fatalf("Start() error:\n%+v", err)
|
||||
}
|
||||
select {
|
||||
case <-ch.migrationsDone:
|
||||
case <-time.After(3 * time.Second):
|
||||
t.Fatalf("Migrations not done")
|
||||
}
|
||||
ch.Stop()
|
||||
}
|
||||
Reference in New Issue
Block a user