Sha256: 9d3ce9677b3215ecdad3f374a768986bf7c2fda83caeec6eba10255519645ce7

Contents?: true

Size: 1.97 KB

Versions: 22

Compression:

Stored size: 1.97 KB

Contents

require_relative "../../../base"

require Vagrant.source_root.join("plugins/provisioners/file/provisioner")

describe VagrantPlugins::FileUpload::Provisioner do
  include_context "unit"

  subject { described_class.new(machine, config) }

  let(:iso_env) do
    # We have to create a Vagrantfile so there is a root path
    env = isolated_environment
    env.vagrantfile("")
    env.create_vagrant_env
  end

  let(:machine) { iso_env.machine(iso_env.machine_names[0], :dummy) }
  let(:config)       { double("config") }
  let(:communicator) { double("comm") }
  let(:guest)        { double("guest") }

  before do
    machine.stub(communicate: communicator)
    machine.stub(guest: guest)

    communicator.stub(execute: true)
    communicator.stub(upload: true)

    guest.stub(capability?: false)
  end

  describe "#provision" do
    it "creates the destination directory" do
      config.stub(source: "/source")
      config.stub(destination: "/foo/bar")

      expect(communicator).to receive(:execute).with("mkdir -p /foo")

      subject.provision
    end

    it "uploads the file" do
      config.stub(source: "/source")
      config.stub(destination: "/foo/bar")

      expect(communicator).to receive(:upload).with("/source", "/foo/bar")

      subject.provision
    end

    it "expands the source file path" do
      config.stub(source: "source")
      config.stub(destination: "/foo/bar")

      expect(communicator).to receive(:upload).with(
        File.expand_path("source"), "/foo/bar")

      subject.provision
    end

    it "expands the destination file path if capable" do
      config.stub(source: "/source")
      config.stub(destination: "$HOME/foo")

      expect(guest).to receive(:capability?).
        with(:shell_expand_guest_path).and_return(true)
      expect(guest).to receive(:capability).
        with(:shell_expand_guest_path, "$HOME/foo").and_return("/home/foo")

      expect(communicator).to receive(:upload).with("/source", "/home/foo")

      subject.provision
    end
  end
end

Version data entries

22 entries across 19 versions & 5 rubygems

Version Path
vagrant-unbundled-1.9.7.1 test/unit/plugins/provisioners/file/provisioner_test.rb
vagrant-aws-mkubenka-0.7.2.pre.14 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/test/unit/plugins/provisioners/file/provisioner_test.rb
vagrant-aws-mkubenka-0.7.2.pre.11 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/test/unit/plugins/provisioners/file/provisioner_test.rb
vagrant-aws-mkubenka-0.7.2.pre.10 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/test/unit/plugins/provisioners/file/provisioner_test.rb
vagrant-aws-mkubenka-0.7.2.pre.9 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/test/unit/plugins/provisioners/file/provisioner_test.rb
vagrant-unbundled-1.9.5.1 test/unit/plugins/provisioners/file/provisioner_test.rb
vagrant-unbundled-1.9.1.1 test/unit/plugins/provisioners/file/provisioner_test.rb
vagrant-compose-yaml-0.1.3 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/test/unit/plugins/provisioners/file/provisioner_test.rb
vagrant-compose-yaml-0.1.2 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/test/unit/plugins/provisioners/file/provisioner_test.rb
vagrant-compose-yaml-0.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/test/unit/plugins/provisioners/file/provisioner_test.rb
vagrant-compose-yaml-0.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/test/unit/plugins/provisioners/file/provisioner_test.rb
vagrant-unbundled-1.8.5.2 test/unit/plugins/provisioners/file/provisioner_test.rb
vagrant-unbundled-1.8.5.1 test/unit/plugins/provisioners/file/provisioner_test.rb
vagrant-unbundled-1.8.4.2 test/unit/plugins/provisioners/file/provisioner_test.rb
vagrant-unbundled-1.8.4.1 test/unit/plugins/provisioners/file/provisioner_test.rb
vagrant-unbundled-1.8.1.2 test/unit/plugins/provisioners/file/provisioner_test.rb
vagrant-unbundled-1.8.1.1 test/unit/plugins/provisioners/file/provisioner_test.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-b421af58e8b3/test/unit/plugins/provisioners/file/provisioner_test.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-1cf2a8db4ccb/test/unit/plugins/provisioners/file/provisioner_test.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-309e896975d1/test/unit/plugins/provisioners/file/provisioner_test.rb