This PR is dependent on the 2.1.0 release of the vagrant_cloud library. It updates the `cloud` command to use the new interface for interacting with the Vagrant Cloud API. It also adds support for direct to backend storage uploads, and defaults to this method. Also included is a bit of cleanup refactoring, addition of method documentation, and fixing up some small issues around custom username usage within the internal client for authentication.
51 lines
1.4 KiB
Ruby
51 lines
1.4 KiB
Ruby
require File.expand_path("../../../base", __FILE__)
|
|
|
|
require "vagrant/util/uploader"
|
|
|
|
describe Vagrant::Util::Uploader do
|
|
let(:destination) { "fake" }
|
|
let(:file) { "my/file.box" }
|
|
let(:curl_options) { [destination, "--request", "PUT", "--upload-file", file, "--fail", {notify: :stderr}] }
|
|
|
|
let(:subprocess_result) do
|
|
double("subprocess_result").tap do |result|
|
|
allow(result).to receive(:exit_code).and_return(exit_code)
|
|
allow(result).to receive(:stderr).and_return("")
|
|
end
|
|
end
|
|
|
|
subject { described_class.new(destination, file, options) }
|
|
|
|
before :each do
|
|
allow(Vagrant::Util::Subprocess).to receive(:execute).and_return(subprocess_result)
|
|
end
|
|
|
|
describe "#upload!" do
|
|
context "with a good exit status" do
|
|
let(:options) { {} }
|
|
let(:exit_code) { 0 }
|
|
|
|
it "uploads the file and returns true" do
|
|
expect(Vagrant::Util::Subprocess).to receive(:execute).
|
|
with("curl", *curl_options).
|
|
and_return(subprocess_result)
|
|
|
|
expect(subject.upload!).to be
|
|
end
|
|
end
|
|
|
|
context "with a bad exit status" do
|
|
let(:options) { {} }
|
|
let(:exit_code) { 1 }
|
|
it "raises an exception" do
|
|
expect(Vagrant::Util::Subprocess).to receive(:execute).
|
|
with("curl", *curl_options).
|
|
and_return(subprocess_result)
|
|
|
|
expect { subject.upload! }.
|
|
to raise_error(Vagrant::Errors::UploaderError)
|
|
end
|
|
end
|
|
end
|
|
end
|