generators: Append empty line to template files
Signed-off-by: Thomas Hipp <thomas.hipp@canonical.com>
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/lxc/lxd/shared/api"
|
||||
|
||||
@ -39,6 +40,11 @@ func (g TemplateGenerator) RunLXD(cacheDir, sourceDir string, img *image.LXDImag
|
||||
|
||||
defer file.Close()
|
||||
|
||||
// Append final new line if missing
|
||||
if !strings.HasSuffix(defFile.Content, "\n") {
|
||||
defFile.Content += "\n"
|
||||
}
|
||||
|
||||
_, err = file.WriteString(defFile.Content)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to write to content to %s template: %s", defFile.Name, err)
|
||||
|
@ -48,7 +48,7 @@ func TestTemplateGeneratorRunLXD(t *testing.T) {
|
||||
t.Fatalf("Unexpected error: %s", err)
|
||||
}
|
||||
|
||||
validateTestFile(t, filepath.Join(cacheDir, "templates", "template.tpl"), "==test==")
|
||||
validateTestFile(t, filepath.Join(cacheDir, "templates", "template.tpl"), "==test==\n")
|
||||
validateTestFile(t, filepath.Join(cacheDir, "rootfs", "root", "template"), "--test--")
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user