Add docker specific tests

This commit is contained in:
sophia 2020-09-14 18:12:58 -05:00
parent da7f957a46
commit a843fd9da7
3 changed files with 73 additions and 4 deletions

View File

@ -0,0 +1,61 @@
# This tests the basic functionality of a provider: that it can run
# a machine, provide SSH access, and destroy that machine.
shared_examples "provider/lifecycle" do |provider, options|
if !options[:image]
raise ArgumentError,
"box option must be specified for provider: #{provider}"
end
include_context "acceptance"
before do
environment.skeleton("basic_docker")
ENV["VAGRANT_SPEC_DOCKER_IMAGE"] = options[:image]
end
let(:opts) { options }
after do
# Just always do this just in case
execute("vagrant", "destroy", "--force", log: false)
end
def assert_running
result = execute("docker", "ps", "--filter", "name=dockertest")
expect(result).to exit_with(0)
expect(result.stdout).to match(/#{opts[:image]}/)
end
def assert_not_running
result = execute("docker", "ps", "--filter", "name=dockertest")
expect(result).to exit_with(0)
# Check the output ends with the last column of the header from the `docker ps`
# command, indicating no images found.
expect(result.stdout).to match(/NAMES\n$/)
end
context "after an up" do
before do
assert_execute("vagrant", "up", "--provider=#{provider}")
end
after do
assert_execute("vagrant", "destroy", "--force")
end
it "can manage machine lifecycle" do
status("Test: machine is running after up")
assert_running
status("Test: halt")
assert_execute("vagrant", "halt")
status("Test: ssh doesn't work during halted state")
assert_not_running
status("Test: up after halt")
assert_execute("vagrant", "up")
assert_running
end
end
end

View File

@ -0,0 +1,8 @@
Vagrant.configure("2") do |config|
config.vm.define "dockertest" do |c|
c.vm.provider "docker" do |d|
d.image = ENV["VAGRANT_SPEC_DOCKER_IMAGE"]
d.remains_running = true
end
end
end

View File

@ -1,11 +1,11 @@
require_relative "../../acceptance/base"
Vagrant::Spec::Acceptance.configure do |c|
c.component_paths << File.expand_path("../test/acceptance", __FILE__)
c.skeleton_paths << File.expand_path("../test/acceptance/skeletons", __FILE__)
c.component_paths << File.expand_path("../../../acceptance", __FILE__)
c.skeleton_paths << File.expand_path("../../../acceptance/skeletons", __FILE__)
# Allow for slow setup to still pass
c.assert_retries = 15
c.provider "docker",
box: ENV["VAGRANT_SPEC_DOCKER_IMAGE"],
contexts: ["provider-context/docker"]
image: ENV["VAGRANT_SPEC_DOCKER_IMAGE"],
box: "placeholder"
end