From 011804e14da1a915aea97983917bac3a63243786 Mon Sep 17 00:00:00 2001 From: Phani Teja Marupaka Date: Thu, 2 Jan 2020 13:06:14 -0800 Subject: [PATCH] Make suggested changes --- api/kv/kv.go | 6 +++--- api/kv/kv_test.go | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/api/kv/kv.go b/api/kv/kv.go index e424fc38b..25a2e8476 100644 --- a/api/kv/kv.go +++ b/api/kv/kv.go @@ -86,13 +86,13 @@ func (kvl *loader) keyValuesFromFileSources(sources []string) ([]types.Pair, err if err != nil { return nil, err } - kvs = append(kvs, types.Pair{Key: k, Value: kvl.trimTrailingSpacesInLines(string(content))}) + kvs = append(kvs, types.Pair{Key: k, Value: trimTrailingSpacesInLines(string(content))}) } return kvs, nil } -// Takes string with multiple lines and trims the trailing white spaces from each line. -func (kvl *loader) trimTrailingSpacesInLines(str string) string { +// trimTrailingSpacesInLines takes string with multiple lines and trims the trailing white spaces and tabs from each line. +func trimTrailingSpacesInLines(str string) string { re := regexp.MustCompile(`\s*\n`) return re.ReplaceAllString(str, "\n") } diff --git a/api/kv/kv_test.go b/api/kv/kv_test.go index d82c4e81c..25b628197 100644 --- a/api/kv/kv_test.go +++ b/api/kv/kv_test.go @@ -97,10 +97,9 @@ func TestKeyValuesFromFileSources(t *testing.T) { } func TestTrimTrailingSpacesInLines(t *testing.T) { - kvl := makeKvLoader(filesys.MakeFsInMemory()) input := "\"fooKey\": \"fooValue\" \t\n\t\"barKey\": \"barValue\"" expected := "\"fooKey\": \"fooValue\"\n\t\"barKey\": \"barValue\"" - res := kvl.trimTrailingSpacesInLines(input) + res := trimTrailingSpacesInLines(input) if !reflect.DeepEqual(res, expected) { t.Errorf("Trim trailing spaces in lines should succeed, got: %s exptected: %s", res, expected) }