mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-09-15 12:18:57 +00:00
Make suggested changes
This commit is contained in:
@@ -86,13 +86,13 @@ func (kvl *loader) keyValuesFromFileSources(sources []string) ([]types.Pair, err
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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
|
return kvs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes string with multiple lines and trims the trailing white spaces from each line.
|
// trimTrailingSpacesInLines takes string with multiple lines and trims the trailing white spaces and tabs from each line.
|
||||||
func (kvl *loader) trimTrailingSpacesInLines(str string) string {
|
func trimTrailingSpacesInLines(str string) string {
|
||||||
re := regexp.MustCompile(`\s*\n`)
|
re := regexp.MustCompile(`\s*\n`)
|
||||||
return re.ReplaceAllString(str, "\n")
|
return re.ReplaceAllString(str, "\n")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,10 +97,9 @@ func TestKeyValuesFromFileSources(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTrimTrailingSpacesInLines(t *testing.T) {
|
func TestTrimTrailingSpacesInLines(t *testing.T) {
|
||||||
kvl := makeKvLoader(filesys.MakeFsInMemory())
|
|
||||||
input := "\"fooKey\": \"fooValue\" \t\n\t\"barKey\": \"barValue\""
|
input := "\"fooKey\": \"fooValue\" \t\n\t\"barKey\": \"barValue\""
|
||||||
expected := "\"fooKey\": \"fooValue\"\n\t\"barKey\": \"barValue\""
|
expected := "\"fooKey\": \"fooValue\"\n\t\"barKey\": \"barValue\""
|
||||||
res := kvl.trimTrailingSpacesInLines(input)
|
res := trimTrailingSpacesInLines(input)
|
||||||
if !reflect.DeepEqual(res, expected) {
|
if !reflect.DeepEqual(res, expected) {
|
||||||
t.Errorf("Trim trailing spaces in lines should succeed, got: %s exptected: %s", res, expected)
|
t.Errorf("Trim trailing spaces in lines should succeed, got: %s exptected: %s", res, expected)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user