Files
akvorado/common/schema/definition_test.go
Vincent Bernat 1ec89aac1f build: fix various lint issues
revive default configuration has changed in 1.3.0. Some stuff is a bit
silly (like empty blocks), but I find it easier to follow that than to
try to tweak the configuration.
2023-03-21 00:01:13 +01:00

69 lines
1.6 KiB
Go

// SPDX-FileCopyrightText: 2022 Free Mobile
// SPDX-License-Identifier: AGPL-3.0-only
package schema
import (
"testing"
"akvorado/common/helpers"
)
func TestFlowsClickHouse(t *testing.T) {
c := NewMock(t)
for _, key := range c.clickHousePrimaryKeys {
if column := c.columnIndex[key]; column.Key == 0 {
t.Errorf("primary key %q not a column", key)
} else {
if column.ClickHouseNotSortingKey {
t.Errorf("primary key %q is marked as a non-sorting key", key)
}
}
}
}
func TestFlowsProtobuf(t *testing.T) {
c := NewMock(t)
for _, column := range c.Columns() {
if column.ProtobufIndex >= 0 {
if column.ProtobufType == 0 {
t.Errorf("column %s has not protobuf type", column.Name)
}
}
}
}
func TestColumnIndex(t *testing.T) {
c := NewMock(t)
for i := ColumnTimeReceived; i < ColumnLast; i++ {
if _, ok := c.LookupColumnByKey(i); !ok {
t.Errorf("column %s cannot be looked up by key", i)
}
}
}
func TestFinalizeTwice(t *testing.T) {
c := NewMock(t)
oldSchema := c.Schema
newSchema := c.finalize()
if diff := helpers.Diff(oldSchema, newSchema, helpers.DiffUnexported); diff != "" {
t.Fatalf("finalize() (-old, +new):\n%s", diff)
}
}
func TestDisabledGroup(t *testing.T) {
c := flows()
if !c.IsDisabled(ColumnGroupNAT) {
t.Error("ColumnGroupNAT is not disabled while it should")
}
if !c.IsDisabled(ColumnGroupL2) {
t.Error("ColumnGroupL2 is not disabled while it should")
}
column, _ := c.LookupColumnByKey(ColumnSrcAddrNAT)
column.Disabled = false
c = c.finalize()
if c.IsDisabled(ColumnGroupNAT) {
t.Error("ColumnGroupNAT is disabled while it should not")
}
}