mikrotik-exporter/config/config_test.go

68 lines
1.7 KiB
Go
Raw Normal View History

package config
import (
"bytes"
"io/ioutil"
"testing"
)
func TestShouldParse(t *testing.T) {
b := loadTestFile(t)
c, err := Load(bytes.NewReader(b))
if err != nil {
t.Fatalf("could not parse: %v", err)
}
if len(c.Devices) != 2 {
t.Fatalf("expected 2 devices, got %v", len(c.Devices))
}
assertDevice("test1", "192.168.1.1", "foo", "bar", c.Devices[0], t)
assertDevice("test2", "192.168.2.1", "test", "123", c.Devices[1], t)
assertFeature("BGP", c.Features.BGP, t)
2020-03-06 22:08:00 +01:00
assertFeature("Conntrack", c.Features.Conntrack, t)
assertFeature("DHCP", c.Features.DHCP, t)
assertFeature("DHCPv6", c.Features.DHCPv6, t)
assertFeature("Pools", c.Features.Pools, t)
assertFeature("Routes", c.Features.Routes, t)
assertFeature("Optics", c.Features.Optics, t)
assertFeature("WlanSTA", c.Features.WlanSTA, t)
assertFeature("WlanIF", c.Features.WlanIF, t)
2019-10-25 03:11:05 +02:00
assertFeature("Ipsec", c.Features.Ipsec, t)
2020-11-22 00:36:27 +01:00
assertFeature("Lte", c.Features.Lte, t)
2020-06-23 11:36:30 +02:00
assertFeature("Netwatch", c.Features.Netwatch, t)
}
func loadTestFile(t *testing.T) []byte {
b, err := ioutil.ReadFile("config.test.yml")
if err != nil {
t.Fatalf("could not load config: %v", err)
}
return b
}
func assertDevice(name, address, user, password string, c Device, t *testing.T) {
if c.Name != name {
t.Fatalf("expected name %s, got %s", name, c.Name)
}
if c.Address != address {
t.Fatalf("expected address %s, got %s", address, c.Address)
}
if c.User != user {
t.Fatalf("expected user %s, got %s", user, c.User)
}
if c.Password != password {
t.Fatalf("expected password %s, got %s", password, c.Password)
}
}
func assertFeature(name string, v bool, t *testing.T) {
if !v {
t.Fatalf("exprected feature %s to be enabled", name)
}
}