56 lines
1.5 KiB
Go

package configloader
import (
"testing"
)
// Tests that the list of parsers is not empty.
func TestListParserReturnsNonEmptyResult(t *testing.T) {
parserList := ListParsers()
if len(parserList) == 0 {
t.Fatalf("The list of returned parsers is empty")
}
}
// Ensures that validating a parser will not accept an invalid parser name.
func TestInvalidParserIsNotAccepted(t *testing.T) {
parser, err := ValidateParser("Liddasfasdo")
if parser != "" {
t.Fatalf("ValidateParser() should return an empty string + error")
}
if err == nil {
t.Fatalf("ValidateParser() did not return an error where it should")
}
}
// Ensures that a parser is valid at its expected name.
func TestValidParserIsAccepted(t *testing.T) {
parser, err := ValidateParser("Lido")
if parser != "Lido" {
t.Fatalf("Test expected validated parser for input 'Lido' to be 'Lido'")
}
if err != nil {
t.Fatalf("ValidateParser() returned an error where it should not")
}
}
// Prepending the prefix "Parser" to a parser name should work as well.
// In this case, the prefix should be removed by ValidateParser().
func TestValidParserIsAcceptedAndCleaned(t *testing.T) {
parser, err := ValidateParser("ParserLido")
if parser != "Lido" {
t.Fatalf("Test expected validated parser for input 'ParserLido' to be 'Lido'")
}
if err != nil {
t.Fatalf("ValidateParser() returned an error where it should not")
}
}