Пример #1
0
func (e *engine) writeTemplate(t tpl.Templater) (err error) {
	f, err := os.Create(filepath.Join(e.outDir, t.BaseFilename()))
	if err != nil {
		return err
	}
	defer func() {
		if cerr := f.Close(); cerr != nil {
			err = cerr
		}
	}()
	w := bufio.NewWriter(f)
	defer func() {
		if cerr := w.Flush(); cerr != nil {
			err = cerr
		}
	}()
	err = e.renderTemplate(t, w)
	return err
}
Пример #2
0
				path := filepath.Join(tmpDir, "nano/packer.json.provisioners.partial")
				Expect(rootTemplate.FindTemplate(path)).ToNot(BeNil())
			})
		})

		Describe("Vagrantfile.template root template", func() {
			var rootTemplate tpl.Templater
			JustBeforeEach(func() {
				rootTemplate = templates.FindTemplate(filepath.Join(tmpDir, "Vagrantfile.template"))
			})
			It("should be found", func() {
				Expect(rootTemplate).ToNot(BeNil())
			})
			It("should have zero partial templates", func() {
				Expect(rootTemplate.ListTemplates()).To(BeEmpty())
			})
			It("should have basefilename", func() {
				Expect(rootTemplate.BaseFilename()).To(Equal("Vagrantfile"))
			})
		})
	})
})

func createTemplateFile(baseDir, path string) {
	fullPath := filepath.Join(baseDir, path)
	fileName := filepath.Base(fullPath)
	fullDir := strings.TrimSuffix(fullPath, fileName)
	os.MkdirAll(fullDir, 0744)
	ioutil.WriteFile(fullPath, []byte(fileName), 0644)
}