1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
require File.expand_path("../../../../../base", __FILE__)
require Vagrant.source_root.join("plugins/commands/box/command/prune")
describe VagrantPlugins::CommandBox::Command::Prune do
include_context "unit"
include_context "command plugin helpers"
let(:entry_klass) { Vagrant::MachineIndex::Entry }
let(:iso_env) do
# We have to create a Vagrantfile so there is a root path
isolated_environment.tap do |env|
env.vagrantfile("")
end
end
let(:iso_vagrant_env) { iso_env.create_vagrant_env }
let(:argv) { [] }
# Seems this way of providing a box version triggers box in use.
def new_entry(name, box_name, box_provider, version)
entry_klass.new.tap do |e|
e.name = name
e.vagrantfile_path = "/bar"
e.extra_data["box"] = {
"name" => box_name,
"provider" => box_provider,
"version" => version,
}
end
end
subject { described_class.new(argv, iso_vagrant_env) }
describe "execute" do
context "with no args" do
it "removes the old version and keeps the current one" do
# Let's put some things in the index
iso_env.box3("foobox", "1.0", :virtualbox);
iso_env.box3("foobox", "1.1", :virtualbox);
iso_env.box3("barbox", "1.0", :vmware);
iso_env.box3("barbox", "1.1", :vmware);
iso_vagrant_env.machine_index.set(new_entry("foo", "foobox", "virtualbox", 1))
output = ""
allow(iso_vagrant_env.ui).to receive(:info) do |data|
output << data
end
expect(iso_vagrant_env.boxes.all.count).to eq(4)
expect(subject.execute).to eq(0)
expect(iso_vagrant_env.boxes.all.count).to eq(2)
expect(output).to include("barbox (vmware, 1.1)")
expect(output).to include("Removing box 'barbox' (v1.0) with provider 'vmware'...")
expect(output).to include("foobox (virtualbox, 1.1)")
expect(output).to include("Removing box 'foobox' (v1.0) with provider 'virtualbox'...")
end
it "removes nothing" do
# Let's put some things in the index
iso_env.box3("foobox", "1.0", :virtualbox);
iso_env.box3("barbox", "1.0", :vmware);
iso_vagrant_env.machine_index.set(new_entry("foo", "foobox", "virtualbox", 1))
output = ""
allow(iso_vagrant_env.ui).to receive(:info) do |data|
output << data
end
expect(iso_vagrant_env.boxes.all.count).to eq(2)
expect(subject.execute).to eq(0)
expect(iso_vagrant_env.boxes.all.count).to eq(2)
expect(output).to include("No old versions of boxes to remove...")
end
end
context "with --provider" do
let(:argv) { ["--provider", "virtualbox"] }
it "removes the old versions of the specified provider" do
# Let's put some things in the index
iso_env.box3("foobox", "1.0", :virtualbox);
iso_env.box3("foobox", "1.1", :virtualbox);
iso_env.box3("barbox", "1.0", :vmware);
iso_env.box3("barbox", "1.1", :vmware);
iso_vagrant_env.machine_index.set(new_entry("foo", "foobox", "virtualbox", 1))
output = ""
allow(iso_vagrant_env.ui).to receive(:info) do |data|
output << "\n" + data
end
expect(iso_vagrant_env.boxes.all.count).to eq(4)
expect(subject.execute).to eq(0)
expect(iso_vagrant_env.boxes.all.count).to eq(3)
expect(output).to include("foobox (virtualbox, 1.1)")
expect(output).to include("Removing box 'foobox' (v1.0) with provider 'virtualbox'...")
end
end
context "with --dry-run" do
let(:argv) { ["--dry-run"] }
it "removes the old versions of the specified provider" do
# Let's put some things in the index
iso_env.box3("foobox", "1.0", :virtualbox);
iso_env.box3("foobox", "1.1", :virtualbox);
iso_vagrant_env.machine_index.set(new_entry("foo", "foobox", "virtualbox", 1))
output = ""
allow(iso_vagrant_env.ui).to receive(:info) do |data|
output << "\n" + data
end
expect(iso_vagrant_env.boxes.all.count).to eq(2)
expect(subject.execute).to eq(0)
expect(iso_vagrant_env.boxes.all.count).to eq(2)
expect(output).to include("foobox (virtualbox, 1.1)")
expect(output).to include("Would remove foobox virtualbox 1.0")
end
end
context "with --name" do
let(:argv) { ["--name", "barbox"] }
it "removes the old versions of the specified provider" do
# Let's put some things in the index
iso_env.box3("foobox", "1.0", :virtualbox);
iso_env.box3("foobox", "1.1", :virtualbox);
iso_env.box3("barbox", "1.0", :vmware);
iso_env.box3("barbox", "1.1", :vmware);
iso_vagrant_env.machine_index.set(new_entry("foo", "foobox", "virtualbox", 1))
output = ""
allow(iso_vagrant_env.ui).to receive(:info) do |data|
output << "\n" + data
end
expect(iso_vagrant_env.boxes.all.count).to eq(4)
expect(subject.execute).to eq(0)
expect(iso_vagrant_env.boxes.all.count).to eq(3)
expect(output).to include("barbox (vmware, 1.1)")
expect(output).to include("Removing box 'barbox' (v1.0) with provider 'vmware'...")
end
end
context "with --name and --provider" do
let(:argv) { ["--name", "foobox", "--provider", "virtualbox"] }
it "removed the old versions of that name and provider only" do
# Let's put some things in the index
iso_env.box3("foobox", "1.0", :virtualbox);
iso_env.box3("foobox", "1.1", :virtualbox);
iso_env.box3("foobox", "1.0", :vmware);
iso_env.box3("foobox", "1.1", :vmware);
iso_env.box3("barbox", "1.0", :vmware);
iso_env.box3("barbox", "1.1", :vmware);
iso_vagrant_env.machine_index.set(new_entry("foo", "foobox", "virtualbox", 1))
output = ""
allow(iso_vagrant_env.ui).to receive(:info) do |data|
output << "\n" + data
end
expect(iso_vagrant_env.boxes.all.count).to eq(6)
expect(subject.execute).to eq(0)
expect(iso_vagrant_env.boxes.all.count).to eq(5)
expect(output).to include("Removing box 'foobox' (v1.0) with provider 'virtualbox'...")
end
end
end
end
|