Skip to content

Commit

Permalink
Add tests for multiple OSes using Vagrant
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Aug 29, 2021
1 parent 08822e2 commit 49c34ea
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.exe
/.vagrant
/bin/chezmoi
/bin/gofumports
/bin/golangci-lint
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions assets/vagrant/fedora33.Vagrantfile
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions assets/vagrant/fedora33.test-chezmoi.sh
Original file line number Diff line number Diff line change
@@ -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 ./... )
9 changes: 9 additions & 0 deletions assets/vagrant/freebsd13.Vagrantfile
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions assets/vagrant/freebsd13.test-chezmoi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

( cd /chezmoi && go test ./... )
9 changes: 9 additions & 0 deletions assets/vagrant/openbsd6.Vagrantfile
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions assets/vagrant/openbsd6.test-chezmoi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

( cd /chezmoi && go test ./... )
15 changes: 15 additions & 0 deletions assets/vagrant/test.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 49c34ea

Please sign in to comment.