mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
This is a first step to make it accept configuration. Most of the changes are quite trivial, but I also ran into some difficulties with query columns and filters. They need the schema for parsing, but parsing happens before dependencies are instantiated (and even if it was not the case, parsing is stateless). Therefore, I have added a `Validate()` method that must be called after instantiation. Various bits `panic()` if not validated to ensure we catch all cases. The alternative to make the component manages a global state would have been simpler but it would break once we add the ability to add or disable columns.
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
// SPDX-FileCopyrightText: 2023 Free Mobile
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
package schema
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestLookupColumnByName(t *testing.T) {
|
|
c := NewMock(t)
|
|
cases := []string{
|
|
"TimeReceived",
|
|
"InIfProvider",
|
|
"OutIfProvider",
|
|
"SrcAS",
|
|
"ForwardingStatus",
|
|
}
|
|
for _, name := range cases {
|
|
column, ok := c.LookupColumnByName(name)
|
|
if !ok {
|
|
t.Fatalf("LookupByName(%q) not found", name)
|
|
}
|
|
if column.Name != name {
|
|
t.Fatalf("LookupByName(%q) == %q but should be %q", name, column.Name, name)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestReverseColumnDirection(t *testing.T) {
|
|
c := NewMock(t)
|
|
cases := []struct {
|
|
Input ColumnKey
|
|
Output ColumnKey
|
|
}{
|
|
{ColumnSrcAS, ColumnDstAS},
|
|
{ColumnDstAS, ColumnSrcAS},
|
|
{ColumnInIfProvider, ColumnOutIfProvider},
|
|
{ColumnOutIfDescription, ColumnInIfDescription},
|
|
{ColumnDstASPath, ColumnDstASPath},
|
|
{ColumnExporterName, ColumnExporterName},
|
|
}
|
|
for _, tc := range cases {
|
|
got := c.ReverseColumnDirection(tc.Input)
|
|
if got != tc.Output {
|
|
t.Errorf("ReverseColumnDirection(%q) == %q but expected %q",
|
|
tc.Input.String(), got.String(), tc.Output.String())
|
|
}
|
|
}
|
|
}
|