From 2fa79c6086b486561cbdb5aa824ede77858a806f Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Wed, 30 Oct 2019 13:48:12 -0700 Subject: [PATCH] fix tests --- .../vagrant/step_create_vagrantfile_test.go | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/builder/vagrant/step_create_vagrantfile_test.go b/builder/vagrant/step_create_vagrantfile_test.go index d81c85107..58df30284 100644 --- a/builder/vagrant/step_create_vagrantfile_test.go +++ b/builder/vagrant/step_create_vagrantfile_test.go @@ -36,10 +36,12 @@ func TestCreateFile(t *testing.T) { expected := `Vagrant.configure("2") do |config| config.vm.define "source", autostart: false do |source| source.vm.box = "apples" + config.ssh.insert_key = false end config.vm.define "output" do |output| output.vm.box = "bananas" output.vm.box_url = "file://package.box" + config.ssh.insert_key = false end config.vm.synced_folder ".", "/vagrant", disabled: true end` @@ -66,10 +68,12 @@ func TestCreateFile_customSync(t *testing.T) { expected := `Vagrant.configure("2") do |config| config.vm.define "source", autostart: false do |source| source.vm.box = "" + config.ssh.insert_key = false end config.vm.define "output" do |output| output.vm.box = "" output.vm.box_url = "file://package.box" + config.ssh.insert_key = false end config.vm.synced_folder "myfolder/foldertimes", "/vagrant" end` @@ -77,3 +81,35 @@ end` t.Fatalf("EXPECTED: \n%s\n\n RECEIVED: \n%s\n\n", expected, actual) } } + +func TestCreateFile_InsertKeyTrue(t *testing.T) { + testy := StepCreateVagrantfile{ + OutputDir: "./", + InsertKey: true, + } + templatePath, err := testy.createVagrantfile() + if err != nil { + t.Fatalf(err.Error()) + } + defer os.Remove(templatePath) + contents, err := ioutil.ReadFile(templatePath) + if err != nil { + t.Fatalf(err.Error()) + } + actual := string(contents) + expected := `Vagrant.configure("2") do |config| + config.vm.define "source", autostart: false do |source| + source.vm.box = "" + config.ssh.insert_key = true + end + config.vm.define "output" do |output| + output.vm.box = "" + output.vm.box_url = "file://package.box" + config.ssh.insert_key = true + end + config.vm.synced_folder ".", "/vagrant", disabled: true +end` + if ok := strings.Compare(actual, expected); ok != 0 { + t.Fatalf("EXPECTED: \n%s\n\n RECEIVED: \n%s\n\n", expected, actual) + } +}