1
0
mirror of https://github.com/alice-lg/alice-lg.git synced 2024-05-11 05:55:03 +00:00
alice-lg-alice-lg/backend/config_test.go

90 lines
2.1 KiB
Go
Raw Normal View History

2017-05-16 18:26:07 +02:00
package main
import (
"testing"
)
// Test configuration loading and parsing
// using the default config
func TestLoadConfigs(t *testing.T) {
2018-07-05 14:41:37 +02:00
config, err := loadConfig("../etc/alicelg/alice.example.conf")
2017-05-17 16:11:52 +02:00
if err != nil {
t.Error("Could not load test config:", err)
}
2017-05-22 11:13:36 +02:00
if config.Server.Listen == "" {
t.Error("Listen string not present.")
}
if len(config.Ui.RoutesColumns) == 0 {
t.Error("Route columns settings missing")
}
if len(config.Ui.RoutesRejections.Reasons) == 0 {
t.Error("Rejection reasons missing")
}
// Check communities
label, err := config.Ui.BgpCommunities.Lookup("1:23")
if err != nil {
t.Error(err)
}
if label != "some tag" {
t.Error("expcted to find example community 1:23 with 'some tag'",
"but got:", label)
}
2017-05-16 18:26:07 +02:00
}
2018-07-05 14:55:12 +02:00
func TestSourceConfigDefaultsOverride(t *testing.T) {
config, err := loadConfig("../etc/alicelg/alice.example.conf")
if err != nil {
t.Error("Could not load test config:", err)
}
// Get sources
rs1 := config.Sources[0]
rs2 := config.Sources[1]
// Source 1 should be on default time
// Source 2 should have an override
// For now it should be sufficient to test if
// the serverTime(rs1) != serverTime(rs2)
if rs1.Birdwatcher.ServerTime == rs2.Birdwatcher.ServerTime {
t.Error("Server times should be different between",
"source 1 and 2 in example configuration",
"(alice.example.conf)")
}
2018-07-05 15:27:03 +02:00
// Check presence of timezone, default: UTC (rs1)
// override: Europe/Bruessels (rs2)
if rs1.Birdwatcher.Timezone != "UTC" {
t.Error("Expected RS1 Timezone to be default: UTC")
}
if rs2.Birdwatcher.Timezone != "Europe/Brussels" {
t.Error("Expected 'Europe/Brussels', got", rs2.Birdwatcher.Timezone)
}
2018-07-05 14:55:12 +02:00
}
2018-09-17 18:17:41 +02:00
func TestBlackholeParsing(t *testing.T) {
config, err := loadConfig("../etc/alicelg/alice.example.conf")
if err != nil {
t.Error("Could not load test config:", err)
}
// Get first source
rs1 := config.Sources[0]
if len(rs1.Blackholes) != 2 {
t.Error("Rs1 should have configured 2 blackholes. Got:", rs1.Blackholes)
return
}
if rs1.Blackholes[0] != "10.23.6.666" {
t.Error("Unexpected blackhole, got:", rs1.Blackholes[0])
}
}