Use bats for unit test with Vagrant
This commit is contained in:
parent
ea5622c61d
commit
47a91a80e5
51
Vagrantfile
vendored
51
Vagrantfile
vendored
|
@ -14,14 +14,37 @@ Vagrant.configure('2') do |config|
|
||||||
libvirt.storage :file, :size => '10G', :device => 'vdb'
|
libvirt.storage :file, :size => '10G', :device => 'vdb'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
$deps = <<SCRIPT
|
||||||
|
DEBIAN_FRONTEND=noninteractive apt-get -yq install openssh-server btrfs-tools rsync lsb-base coreutils sed dash mount openssh-sftp-server libc6 bash-completion
|
||||||
|
SCRIPT
|
||||||
|
|
||||||
|
$part = <<SCRIPT
|
||||||
|
lsof|awk '/backup/ { print $2 }'| xargs --no-run-if-empty kill -9
|
||||||
|
grep -q /backup /proc/mounts && umount -R /backup
|
||||||
|
mkfs.btrfs -f /dev/vdb
|
||||||
|
mkdir -p /backup
|
||||||
|
mount /dev/vdb /backup
|
||||||
|
SCRIPT
|
||||||
|
|
||||||
config.vm.define :jessie do |node|
|
config.vm.define :jessie do |node|
|
||||||
node.vm.hostname = "bkctld-jessie"
|
node.vm.hostname = "bkctld-jessie"
|
||||||
node.vm.box = "debian/jessie64"
|
node.vm.box = "debian/jessie64"
|
||||||
|
config.vm.provision "backports", type: "shell" do |s|
|
||||||
|
s.inline = "echo 'deb http://deb.debian.org/debian jessie-backports main' > /etc/apt/sources.list.d/backports.list && apt-get update"
|
||||||
|
end
|
||||||
|
config.vm.provision "deps", type: "shell", :inline => $deps
|
||||||
|
config.vm.provision "bats", type: "shell", :inline => "DEBIAN_FRONTEND=noninteractive apt-get -yq install -t jessie-backports bats"
|
||||||
|
config.vm.provision "part", type: "shell", :inline => $part
|
||||||
|
config.vm.provision "test", type: "shell", :path => "./test/main.bats"
|
||||||
end
|
end
|
||||||
|
|
||||||
config.vm.define :stretch do |node|
|
config.vm.define :stretch do |node|
|
||||||
node.vm.hostname = "bkctld-stretch"
|
node.vm.hostname = "bkctld-stretch"
|
||||||
node.vm.box = "debian/stretch64"
|
node.vm.box = "debian/stretch64"
|
||||||
|
config.vm.provision "deps", type: "shell", :inline => $deps
|
||||||
|
config.vm.provision "bats", type: "shell", :inline => "DEBIAN_FRONTEND=noninteractive apt-get -yq install bats"
|
||||||
|
config.vm.provision "part", type: "shell", :inline => $part
|
||||||
|
config.vm.provision "test", type: "shell", :path => "./test/main.bats"
|
||||||
end
|
end
|
||||||
|
|
||||||
config.vm.provision "copy", type: "file" do |f|
|
config.vm.provision "copy", type: "file" do |f|
|
||||||
|
@ -29,10 +52,6 @@ Vagrant.configure('2') do |config|
|
||||||
f.destination = "~/bkctld/"
|
f.destination = "~/bkctld/"
|
||||||
end
|
end
|
||||||
|
|
||||||
config.vm.provision "deps", type: "shell" do |s|
|
|
||||||
s.inline = "DEBIAN_FRONTEND=noninteractive apt-get -yq install openssh-server btrfs-tools rsync lsb-base coreutils sed dash mount openssh-sftp-server libc6 bash-completion"
|
|
||||||
end
|
|
||||||
|
|
||||||
$install = <<SCRIPT
|
$install = <<SCRIPT
|
||||||
ln -fs /home/vagrant/bkctld/bkctld /usr/sbin/bkctld
|
ln -fs /home/vagrant/bkctld/bkctld /usr/sbin/bkctld
|
||||||
ln -fs /home/vagrant/bkctld/tpl /usr/share/bkctld
|
ln -fs /home/vagrant/bkctld/tpl /usr/share/bkctld
|
||||||
|
@ -43,28 +62,4 @@ SCRIPT
|
||||||
config.vm.provision "install", type: "shell" do |s|
|
config.vm.provision "install", type: "shell" do |s|
|
||||||
s.inline = $install
|
s.inline = $install
|
||||||
end
|
end
|
||||||
|
|
||||||
$part = <<SCRIPT
|
|
||||||
lsof|awk '/backup/ { print $2 }'| xargs --no-run-if-empty kill -9
|
|
||||||
grep -q /backup /proc/mounts && umount -R /backup
|
|
||||||
mkfs.btrfs -f /dev/vdb
|
|
||||||
mkdir -p /backup
|
|
||||||
mount /dev/vdb /backup
|
|
||||||
SCRIPT
|
|
||||||
|
|
||||||
config.vm.provision "part", type: "shell" do |s|
|
|
||||||
s.inline = $part
|
|
||||||
end
|
|
||||||
|
|
||||||
$bkctld = <<SCRIPT
|
|
||||||
rm -f /root/bkctld.key* && ssh-keygen -t rsa -N "" -f /root/bkctld.key -q
|
|
||||||
bkctld init test
|
|
||||||
bkctld key test /root/bkctld.key.pub
|
|
||||||
bkctld start test
|
|
||||||
ssh -p 2223 -i /root/bkctld.key -oStrictHostKeyChecking=no root@127.0.0.1 lastlog -u root
|
|
||||||
SCRIPT
|
|
||||||
|
|
||||||
config.vm.provision "bkctld", type: "shell" do |s|
|
|
||||||
s.inline = $bkctld
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
22
test/main.bats
Executable file
22
test/main.bats
Executable file
|
@ -0,0 +1,22 @@
|
||||||
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
rm -f /root/bkctld.key* && ssh-keygen -t rsa -N "" -f /root/bkctld.key -q
|
||||||
|
bkctld init test
|
||||||
|
bkctld key test /root/bkctld.key.pub
|
||||||
|
bkctld start test
|
||||||
|
}
|
||||||
|
|
||||||
|
teardown() {
|
||||||
|
bkctld remove test
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "simple ssh" {
|
||||||
|
ssh -p 2223 -i /root/bkctld.key -oStrictHostKeyChecking=no root@127.0.0.1 lastlog -u root
|
||||||
|
[ "$?" -eq 0 ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "rsync" {
|
||||||
|
rsync -a -e "ssh -p 2223 -i /root/bkctld.key -oStrictHostKeyChecking=no" /tmp/ root@127.0.0.1:/var/backup/
|
||||||
|
[ "$?" -eq 0 ]
|
||||||
|
}
|
Loading…
Reference in a new issue