fixed test

This commit is contained in:
Annika Hannig 2023-11-22 16:58:25 +01:00
parent be5568d530
commit 4e7330b4f3
No known key found for this signature in database
GPG Key ID: 62E226E47DDCE58D
2 changed files with 24 additions and 3 deletions

View File

@ -5,6 +5,7 @@
package config
import (
"bytes"
"errors"
"fmt"
"log"
@ -822,15 +823,35 @@ func getSources(config *ini.File) ([]*SourceConfig, error) {
return sources, nil
}
// preprocessConfig parses the variables section of the config
// and applies it to the rest of the config.
func preprocessConfig(data []byte) []byte {
lines := bytes.Split(data, []byte("\n"))
config := make([][]byte, 0, len(lines))
for _, line := range lines {
config = append(config, line)
}
return bytes.Join(config, []byte("\n"))
}
// LoadConfig reads a configuration from a file.
func LoadConfig(file string) (*Config, error) {
// Try to get config file, fallback to alternatives
file, err := getConfigFile(file)
if err != nil {
return nil, err
}
// Read the config file and preprocess it
configData, err := os.ReadFile(file)
if err != nil {
return nil, err
}
configData = preprocessConfig(configData)
// Load configuration, but handle bgp communities section
// with our own parser
parsedConfig, err := ini.LoadSources(ini.LoadOptions{
@ -840,7 +861,7 @@ func LoadConfig(file string) (*Config, error) {
"rejection_reasons",
"noexport_reasons",
},
}, file)
}, configData)
if err != nil {
return nil, err
}

View File

@ -9,7 +9,7 @@ import (
// Compile input pattern regex
var (
expandMatchPlaceholder = regexp.MustCompile(`(?U:{.*}+?)`)
expandMatchWildcardShorthard = regexp.MustCompile(`(?U:{{.*}}+?)`)
expandMatchWildcardShorthard = regexp.MustCompile(`(?U:{{.*\*}}+?)`)
)
// Extract all matches from the input string.