start integration tests + add test for resource/command

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
Dominik Richter 2015-09-03 13:22:15 +02:00
parent 18701752a7
commit a005add5ae
3 changed files with 78 additions and 0 deletions

View file

@ -15,4 +15,40 @@ namespace :test do
sh(Gem.ruby, '-w', '-Ilib:test', file)
end or raise "Failures"
end
task :integration do
require 'docker'
require 'yaml'
tests = Dir["test/resource/*.rb"]
return if tests.empty?
images = {}
Docker::Image.all.map do |img|
Array(img.info['RepoTags']).each do |tag|
images[tag] = img
end
end
conf = YAML.load(File::read '.tests.yaml')
conf['images'].each do |name|
dname = "docker-#{name}:latest"
image = images[dname]
raise "Can't find docker image #{dname}" if image.nil?
container = Docker::Container.create(
'Cmd' => [ '/bin/bash' ],
'Image' => image.id,
'OpenStdin' => true,
)
container.start
res = sh(Gem.ruby, '-I', 'lib', 'test/docker.rb', container.id, *tests)
container.kill
container.delete(force: true)
res
end.all? or raise "Failures"
end
end

12
test/docker.rb Normal file
View file

@ -0,0 +1,12 @@
require_relative '../lib/vulcano'
docker_id = ARGV[0]
raise 'You must provide a valid docker container ID' if docker_id.nil?
tests = ARGV.drop(1)
exit 0 if tests.empty?
opts = { target: "docker://#{docker_id}" }
runner = Vulcano::Runner.new(nil, opts)
p "Create runner at #{opts}"
runner.add_tests(tests)
runner.run

30
test/resource/command.rb Normal file
View file

@ -0,0 +1,30 @@
describe command('echo hello') do
its(:stdout) { should eq "hello\n" }
its(:stderr) { should eq "" }
its(:exit_status) { should eq 0 }
end
describe command('>&2 echo error') do
its(:stdout) { should eq "" }
its(:stderr) { should eq "error\n" }
its(:exit_status) { should eq 0 }
end
describe command('exit 123') do
its(:stdout) { should eq "" }
its(:stderr) { should eq "" }
its(:exit_status) { should eq 123 }
end
describe command('/bin/sh').exists? do
it { should eq true }
end
describe command('sh').exists? do
it { should eq true }
end
describe command('this is not existing').exists? do
it { should eq false }
end