generators: Append empty line to template files

Signed-off-by: Thomas Hipp <thomas.hipp@canonical.com>
This commit is contained in:
Thomas Hipp
2018-06-28 18:19:38 +02:00
parent 334b658b99
commit 209ebeec86
2 changed files with 7 additions and 1 deletions

View File

@ -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)

View File

@ -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--")
}