Sha256: 3272089041a7ac10eefa45c8695d895248b06d08f6ada7199dd93d727472c8e1

Contents?: true

Size: 1.83 KB

Versions: 9

Compression:

Stored size: 1.83 KB

Contents

require 'spec_helper'

describe VagrantWindows::Communication::WinRMCommunicator, :integration => true do
  
  before(:all) do
    # This test requires you already have a running Windows Server 2008 R2 Vagrant VM
    # Not ideal, but you have to start somewhere
    @communicator = VagrantWindows::Communication::WinRMCommunicator.new({})
    @communicator.winrmshell = VagrantWindows::Communication::WinRMShell.new("127.0.0.1", "vagrant", "vagrant")
  end
  
  describe "execute" do
    it "should return 1 when error_check is false" do
      expect(@communicator.execute("exit 1", { :error_check => false })).to eq(1)
    end
    
    it "should raise WinRMExecutionError when error_check is true" do
      expect { @communicator.execute("exit 1") }.to raise_error(VagrantWindows::Errors::WinRMExecutionError)
    end
    
    it "should raise specified error type when specified and error_check is true" do
      opts = { :error_class => VagrantWindows::Errors::WinRMInvalidShell }
      expect { @communicator.execute("exit 1", opts) }.to raise_error(VagrantWindows::Errors::WinRMInvalidShell)
    end
  end
  
  describe "upload" do
    it "should upload the file and overwrite it if it exists" do
      test_file = Tempfile.new("uploadtest")
      IO.write(test_file, "hello world")
      @communicator.upload(test_file, "c:\\vagrantuploadtest.txt")
      
      # ensure we can overwrite
      IO.write(test_file, "goodbye cruel world")
      @communicator.upload(test_file, "c:\\vagrantuploadtest.txt")
      
      # get the uploaded file's contents to ensure it uploaded properly
      uploaded_file_content = ''
      @communicator.execute("cat c:\\vagrantuploadtest.txt", {}) do |type, line|
        uploaded_file_content = uploaded_file_content + line
      end
      
      expect(uploaded_file_content.chomp).to eq("goodbye cruel world")
    end
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
vagrant-windows-1.6.0 spec/vagrant-windows/winrmcommunicator_spec.rb
vagrant-windows-1.6.0.pre.1 spec/vagrant-windows/winrmcommunicator_spec.rb
vagrant-windows-1.5.1 spec/vagrant-windows/winrmcommunicator_spec.rb
vagrant-windows-1.5.0 spec/vagrant-windows/winrmcommunicator_spec.rb
vagrant-windows-1.4.0 spec/vagrant-windows/winrmcommunicator_spec.rb
vagrant-windows-1.3.2 spec/vagrant-windows/winrmcommunicator_spec.rb
vagrant-windows-1.3.1 spec/vagrant-windows/winrmcommunicator_spec.rb
vagrant-windows-1.3.0 spec/vagrant-windows/winrmcommunicator_spec.rb
vagrant-windows-1.3.0.pre.3 spec/vagrant-windows/winrmcommunicator_spec.rb