mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-12 06:24:10 +01:00
orchestrator/clickhouse: run some tests without a ClickHouse database
Some tests don't rely on the ClickHouse database at all. Allow them to run without it.
This commit is contained in:
@@ -6,7 +6,6 @@ package clickhouse
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"akvorado/common/clickhousedb"
|
||||
"akvorado/common/daemon"
|
||||
"akvorado/common/helpers"
|
||||
"akvorado/common/httpserver"
|
||||
@@ -17,7 +16,6 @@ import (
|
||||
|
||||
func TestHTTPEndpoints(t *testing.T) {
|
||||
r := reporter.NewMock(t)
|
||||
clickhouseComponent := clickhousedb.SetupClickHouse(t, r, false)
|
||||
config := DefaultConfiguration()
|
||||
config.SkipMigrations = true
|
||||
config.Networks = helpers.MustNewSubnetMap(map[string]NetworkAttributes{
|
||||
@@ -43,7 +41,7 @@ func TestHTTPEndpoints(t *testing.T) {
|
||||
HTTP: httpserver.NewMock(t, r),
|
||||
Schema: sch,
|
||||
GeoIP: geoip.NewMock(t, r, false),
|
||||
ClickHouse: clickhouseComponent,
|
||||
ClickHouse: nil,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("New() error:\n%+v", err)
|
||||
@@ -95,7 +93,6 @@ func TestHTTPEndpoints(t *testing.T) {
|
||||
|
||||
func TestAdditionalASNs(t *testing.T) {
|
||||
r := reporter.NewMock(t)
|
||||
clickhouseComponent := clickhousedb.SetupClickHouse(t, r, false)
|
||||
config := DefaultConfiguration()
|
||||
config.ASNs = map[uint32]string{
|
||||
1: "New network",
|
||||
@@ -105,7 +102,7 @@ func TestAdditionalASNs(t *testing.T) {
|
||||
HTTP: httpserver.NewMock(t, r),
|
||||
Schema: schema.NewMock(t),
|
||||
GeoIP: geoip.NewMock(t, r, false),
|
||||
ClickHouse: clickhouseComponent,
|
||||
ClickHouse: nil,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("New() error:\n%+v", err)
|
||||
|
||||
@@ -184,5 +184,8 @@ func (c *Component) guessHTTPBaseURL(ip string) (string, error) {
|
||||
|
||||
// ReloadDictionary will reload the specified dictionnary.
|
||||
func (c *Component) ReloadDictionary(ctx context.Context, dictName string) error {
|
||||
if c.d.ClickHouse != nil {
|
||||
return c.d.ClickHouse.ExecOnCluster(ctx, fmt.Sprintf("SYSTEM RELOAD DICTIONARY %s.%s", c.d.ClickHouse.DatabaseName(), dictName))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"akvorado/common/clickhousedb"
|
||||
"akvorado/common/daemon"
|
||||
"akvorado/common/helpers"
|
||||
"akvorado/common/httpserver"
|
||||
@@ -21,7 +20,6 @@ func TestNetworksCSVWithGeoip(t *testing.T) {
|
||||
config := DefaultConfiguration()
|
||||
config.SkipMigrations = true
|
||||
r := reporter.NewMock(t)
|
||||
clickhouseComponent := clickhousedb.SetupClickHouse(t, r, false)
|
||||
|
||||
t.Run("only GeoIP", func(t *testing.T) {
|
||||
// First use only GeoIP
|
||||
@@ -30,7 +28,7 @@ func TestNetworksCSVWithGeoip(t *testing.T) {
|
||||
HTTP: httpserver.NewMock(t, r),
|
||||
Schema: schema.NewMock(t),
|
||||
GeoIP: geoip.NewMock(t, r, true),
|
||||
ClickHouse: clickhouseComponent,
|
||||
ClickHouse: nil,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("New() error:\n%+v", err)
|
||||
@@ -79,7 +77,7 @@ func TestNetworksCSVWithGeoip(t *testing.T) {
|
||||
HTTP: httpserver.NewMock(t, r),
|
||||
Schema: schema.NewMock(t),
|
||||
GeoIP: geoip.NewMock(t, r, true),
|
||||
ClickHouse: clickhouseComponent,
|
||||
ClickHouse: nil,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("New() error:\n%+v", err)
|
||||
@@ -130,7 +128,7 @@ func TestNetworksCSVWithGeoip(t *testing.T) {
|
||||
HTTP: httpserver.NewMock(t, r),
|
||||
Schema: schema.NewMock(t),
|
||||
GeoIP: geoip.NewMock(t, r, true),
|
||||
ClickHouse: clickhouseComponent,
|
||||
ClickHouse: nil,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("New() error:\n%+v", err)
|
||||
|
||||
@@ -104,6 +104,7 @@ func (c *Component) Start() error {
|
||||
})
|
||||
|
||||
// Database migration
|
||||
if c.d.ClickHouse != nil {
|
||||
migrationsOnce := false
|
||||
c.metrics.migrationsRunning.Set(1)
|
||||
c.t.Go(func() error {
|
||||
@@ -132,6 +133,7 @@ func (c *Component) Start() error {
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Network sources update
|
||||
if err := c.networkSourcesFetcher.Start(); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user