Add tests for the string splitting function.

This commit is contained in:
Oleksii Kliukin
2017-11-22 10:43:35 +01:00
parent e95f80e351
commit 2079d811b4
2 changed files with 38 additions and 7 deletions
+32
View File
@@ -0,0 +1,32 @@
package config
import (
"testing"
"reflect"
"fmt"
)
var getMapPairsFromStringTest = []struct {
in string
expected []string
err error
}{
{"log_statement:all, work_mem:'4GB'", []string{"log_statement:all", "work_mem:'4GB'"}, nil},
{`log_statement:none, search_path:'"$user", public'`, []string{"log_statement:none", `search_path:'"$user", public'`}, nil},
{`search_path:'"$user"`, nil, fmt.Errorf("unclosed quote starting at position 13")},
{"", []string{""}, nil},
{",,log_statement:all ,", []string{"","","log_statement:all", ""}, nil},
}
func TestGetMapPairsFromString(t *testing.T) {
for _, tt := range getMapPairsFromStringTest {
got, err := getMapPairsFromString(tt.in)
if err != tt.err && ((err == nil || tt.err == nil) || (err.Error() != tt.err.Error())) {
t.Errorf("TestGetMapPairsFromString with %s: expected error: %#v, got %#v", tt.in, tt.err, err)
}
if !reflect.DeepEqual(got, tt.expected) {
t.Errorf("TestGetMapPairsFromString with %s: expected %#v, got %#v", tt.in, tt.expected, got)
}
}
}