"Fossies" - the Fresh Open Source Software Archive

Member "vagrant-2.2.14/test/unit/plugins/pushes/ftp/adapter_test.rb" (20 Nov 2020, 2482 Bytes) of package /linux/misc/vagrant-2.2.14.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Ruby source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 require_relative "../../../base"
    2 require "fake_ftp"
    3 
    4 require Vagrant.source_root.join("plugins/pushes/ftp/adapter")
    5 
    6 describe VagrantPlugins::FTPPush::Adapter do
    7   include_context "unit"
    8 
    9   subject do
   10     described_class.new("127.0.0.1:2345", "sethvargo", "bacon",
   11       foo: "bar",
   12     )
   13   end
   14 
   15   describe "#initialize" do
   16     it "sets the instance variables" do
   17       expect(subject.host).to eq("127.0.0.1")
   18       expect(subject.port).to eq(2345)
   19       expect(subject.username).to eq("sethvargo")
   20       expect(subject.password).to eq("bacon")
   21       expect(subject.options).to eq(foo: "bar")
   22       expect(subject.server).to be(nil)
   23     end
   24   end
   25 
   26   describe "#parse_host" do
   27     it "has a default value" do
   28       allow(subject).to receive(:default_port)
   29         .and_return(5555)
   30 
   31       result = subject.parse_host("127.0.0.1")
   32       expect(result[0]).to eq("127.0.0.1")
   33       expect(result[1]).to eq(5555)
   34     end
   35   end
   36 end
   37 
   38 describe VagrantPlugins::FTPPush::FTPAdapter do
   39   include_context "unit"
   40 
   41   before(:all) do
   42     @server = nil
   43     with_random_port do |port1, port2|
   44       @server = FakeFtp::Server.new(port1, port2)
   45     end
   46     @server.start
   47   end
   48 
   49   after(:all) { @server.stop }
   50 
   51   let(:server) { @server }
   52 
   53   before { server.reset }
   54 
   55   subject do
   56     described_class.new("127.0.0.1:#{server.port}", "sethvargo", "bacon")
   57   end
   58 
   59   describe "#default_port" do
   60     it "is 21" do
   61       expect(subject.default_port).to eq(21)
   62     end
   63   end
   64 
   65   describe "#upload" do
   66     before do
   67       @dir = Dir.mktmpdir("vagrant-ftp-push-adapter-upload")
   68       FileUtils.touch("#{@dir}/file")
   69     end
   70 
   71     after do
   72       FileUtils.rm_rf(@dir)
   73     end
   74 
   75     it "uploads the file" do
   76       subject.connect do |ftp|
   77         ftp.upload("#{@dir}/file", "/file")
   78       end
   79 
   80       expect(server.files).to include("file")
   81     end
   82 
   83     it "uploads in passive mode" do
   84       subject.options[:passive] = true
   85       subject.connect do |ftp|
   86         ftp.upload("#{@dir}/file", "/file")
   87       end
   88 
   89       expect(server.file("file")).to be_passive
   90     end
   91   end
   92 end
   93 
   94 describe VagrantPlugins::FTPPush::SFTPAdapter do
   95   include_context "unit"
   96 
   97   subject do
   98     described_class.new("127.0.0.1:2345", "sethvargo", "bacon",
   99       foo: "bar",
  100     )
  101   end
  102 
  103   describe "#default_port" do
  104     it "is 22" do
  105       expect(subject.default_port).to eq(22)
  106     end
  107   end
  108 
  109   describe "#upload" do
  110     it "uploads the file" do
  111       pending "a way to mock an SFTP server"
  112       test_with_mock_sftp_server
  113     end
  114   end
  115 end