From 49c34ea3629cd0d8f5b386b15f2b5eee6139ca03 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 30 Aug 2021 01:17:38 +0200 Subject: [PATCH] Add tests for multiple OSes using Vagrant --- .gitignore | 1 + Makefile | 4 ++++ assets/vagrant/fedora33.Vagrantfile | 9 +++++++++ assets/vagrant/fedora33.test-chezmoi.sh | 5 +++++ assets/vagrant/freebsd13.Vagrantfile | 9 +++++++++ assets/vagrant/freebsd13.test-chezmoi.sh | 3 +++ assets/vagrant/openbsd6.Vagrantfile | 9 +++++++++ assets/vagrant/openbsd6.test-chezmoi.sh | 3 +++ assets/vagrant/test.sh | 15 +++++++++++++++ 9 files changed, 58 insertions(+) create mode 100644 assets/vagrant/fedora33.Vagrantfile create mode 100644 assets/vagrant/fedora33.test-chezmoi.sh create mode 100644 assets/vagrant/freebsd13.Vagrantfile create mode 100644 assets/vagrant/freebsd13.test-chezmoi.sh create mode 100644 assets/vagrant/openbsd6.Vagrantfile create mode 100644 assets/vagrant/openbsd6.test-chezmoi.sh create mode 100755 assets/vagrant/test.sh diff --git a/.gitignore b/.gitignore index 7cb1c45b521..6a14a5e3bca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.exe +/.vagrant /bin/chezmoi /bin/gofumports /bin/golangci-lint diff --git a/Makefile b/Makefile index 8bcc094763f..986a5194c2b 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,10 @@ test: ${GO} test -ldflags="-X github.com/twpayne/chezmoi/internal/chezmoitest.umaskStr=0o022" ./... ${GO} test -ldflags="-X github.com/twpayne/chezmoi/internal/chezmoitest.umaskStr=0o002" ./... +.PHONY: test-os +test-os: + ( cd assets/vagrant && ./test.sh fedora33 freebsd13 openbsd6 ) + .PHONY: coverage-html coverage-html: coverage ${GO} tool cover -html=coverage.out diff --git a/assets/vagrant/fedora33.Vagrantfile b/assets/vagrant/fedora33.Vagrantfile new file mode 100644 index 00000000000..8bc8084034a --- /dev/null +++ b/assets/vagrant/fedora33.Vagrantfile @@ -0,0 +1,9 @@ +Vagrant.configure("2") do |config| + config.vm.box = "generic/fedora33" + config.vm.hostname = "fedora33" + config.vm.synced_folder ".", "/chezmoi", type: "rsync" + config.vm.provision "shell", inline: <<-SHELL + yum install --quiet --assumeyes git gnupg golang + SHELL + config.vm.provision "file", source: "assets/vagrant/fedora33.test-chezmoi.sh", destination: "test-chezmoi.sh" +end diff --git a/assets/vagrant/fedora33.test-chezmoi.sh b/assets/vagrant/fedora33.test-chezmoi.sh new file mode 100644 index 00000000000..35d2f3554df --- /dev/null +++ b/assets/vagrant/fedora33.test-chezmoi.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +go get golang.org/dl/go1.17 +"$HOME"/go/bin/go1.17 download +( cd /chezmoi && "$HOME"/go/bin/go1.17 test ./... ) diff --git a/assets/vagrant/freebsd13.Vagrantfile b/assets/vagrant/freebsd13.Vagrantfile new file mode 100644 index 00000000000..72427967865 --- /dev/null +++ b/assets/vagrant/freebsd13.Vagrantfile @@ -0,0 +1,9 @@ +Vagrant.configure("2") do |config| + config.vm.box = "generic/freebsd13" + config.vm.hostname = "freebsd13" + config.vm.synced_folder ".", "/chezmoi", type: "rsync" + config.vm.provision "shell", inline: <<-SHELL + pkg install --quiet --yes git gnupg go + SHELL + config.vm.provision "file", source: "assets/vagrant/freebsd13.test-chezmoi.sh", destination: "test-chezmoi.sh" +end diff --git a/assets/vagrant/freebsd13.test-chezmoi.sh b/assets/vagrant/freebsd13.test-chezmoi.sh new file mode 100644 index 00000000000..ffeef72de3c --- /dev/null +++ b/assets/vagrant/freebsd13.test-chezmoi.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +( cd /chezmoi && go test ./... ) diff --git a/assets/vagrant/openbsd6.Vagrantfile b/assets/vagrant/openbsd6.Vagrantfile new file mode 100644 index 00000000000..70d50758fe9 --- /dev/null +++ b/assets/vagrant/openbsd6.Vagrantfile @@ -0,0 +1,9 @@ +Vagrant.configure("2") do |config| + config.vm.box = "generic/openbsd6" + config.vm.hostname = "openbsd6" + config.vm.synced_folder ".", "/chezmoi", type: "rsync" + config.vm.provision "shell", inline: <<-SHELL + pkg_add -x git gnupg go + SHELL + config.vm.provision "file", source: "assets/vagrant/openbsd6.test-chezmoi.sh", destination: "test-chezmoi.sh" +end diff --git a/assets/vagrant/openbsd6.test-chezmoi.sh b/assets/vagrant/openbsd6.test-chezmoi.sh new file mode 100644 index 00000000000..ffeef72de3c --- /dev/null +++ b/assets/vagrant/openbsd6.test-chezmoi.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +( cd /chezmoi && go test ./... ) diff --git a/assets/vagrant/test.sh b/assets/vagrant/test.sh new file mode 100755 index 00000000000..01b61f6fbaf --- /dev/null +++ b/assets/vagrant/test.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +for os in "$@"; do + if [ -f "${os}.Vagrantfile" ]; then + export VAGRANT_VAGRANTFILE=assets/vagrant/${os}.Vagrantfile + ( + cd ../.. && + vagrant up && + vagrant ssh -c "sh test-chezmoi.sh" && + vagrant destroy -f + ) + else + echo "${os}.Vagrantfile not found" + fi +done