func run(c *cli.Context) { config, err := loadConfiguration(c) if err != nil { die("Couldn't load the inductor.json configuration file.", err) } opts, err := createRenderOpts(c, config) if err != nil { die(err) } outDir, err := outDir(c, config) if err != nil { die(err) } // find all templates cwd, err := os.Getwd() if err != nil { die(err) } templates := tpl.New(cwd, opts.OSName) // render all the templates to the output directory renderer := renderer.New(opts, outDir) err = renderer.Render(templates) if err != nil { die(err) } // copy over any non-templates to the output directory copier := cpy.New() err = copier.Copy(cwd, outDir) if err != nil { die(err) } }
outDir string vagrantfilePath string ) Describe("Vagrantfile template", func() { BeforeEach(func() { outDir, err = ioutil.TempDir("", "inductor") Expect(err).NotTo(HaveOccurred()) vagrantfilePath = filepath.Join(outDir, "Vagrantfile") renderOptions = renderer.NewDefaultRenderOptions() vagrantTemplate := new(fakes.FakeTemplater) vagrantTemplate.ContentStub = writeVagrantfile vagrantTemplate.BaseFilenameReturns("Vagrantfile") templates = new(fakes.FakeTemplateContainer) templates.ListTemplatesReturns([]tpl.Templater{vagrantTemplate}) engine = renderer.New(renderOptions, outDir) err = engine.Render(templates) }) AfterEach(func() { os.RemoveAll(outDir) }) It("should not have errored", func() { Expect(err).NotTo(HaveOccurred()) }) It("should render Vagrantfile in out dir", func() { Expect(vagrantfilePath).To(BeARegularFile()) }) It("should contain Vagrant configure block", func() { bytes, err := ioutil.ReadFile(vagrantfilePath) Expect(err).NotTo(HaveOccurred()) Expect(string(bytes)).To(ContainSubstring("Vagrant.configure(\"2\") do |config|"))