From 80efab978f07d42922c3e447d9f5873f6ac60717 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sat, 2 Oct 2021 13:10:25 +0000 Subject: [PATCH] chore: Minor test fixes --- .github/workflows/main.yml | 2 +- Makefile | 4 ++++ assets/docker/fedora.Dockerfile | 3 ++- assets/docker/fedora.entrypoint.sh | 11 +++++++++++ internal/cmd/config_test.go | 16 +++++++--------- internal/cmd/testdata/scripts/workingtree.txt | 11 ++++++++++- 6 files changed, 35 insertions(+), 12 deletions(-) create mode 100755 assets/docker/fedora.entrypoint.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8cd2a6bc963..011f6b647d6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -217,7 +217,7 @@ jobs: [Environment]::SetEnvironmentVariable("Path", $env:PATH, "Machine") choco install --no-progress --yes gpg4win echo "C:\Program Files (x86)\GnuPG\bin" >> $env:GITHUB_PATH - - name: Upload chocolatey + - name: Upload chocolatey log if: failure() uses: actions/upload-artifact@v2 with: diff --git a/Makefile b/Makefile index bac3aed6867..3bc8dd0e854 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,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-docker +test-docker: + ( cd assets/docker && ./test.sh archlinux fedora voidlinux ) + .PHONY: test-vagrant test-vagrant: ( cd assets/vagrant && ./test.sh debian11-i386 freebsd13 openbsd6 ) diff --git a/assets/docker/fedora.Dockerfile b/assets/docker/fedora.Dockerfile index 22a42550344..623c931f036 100644 --- a/assets/docker/fedora.Dockerfile +++ b/assets/docker/fedora.Dockerfile @@ -2,4 +2,5 @@ FROM fedora:latest RUN dnf update -y && \ dnf install -y bzip2 git gnupg golang -ENTRYPOINT ( cd /chezmoi && go test ./... ) +COPY assets/docker/fedora.entrypoint.sh /entrypoint.sh +ENTRYPOINT /entrypoint.sh diff --git a/assets/docker/fedora.entrypoint.sh b/assets/docker/fedora.entrypoint.sh new file mode 100755 index 00000000000..1a822697670 --- /dev/null +++ b/assets/docker/fedora.entrypoint.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -eufo pipefail + +GO_VERSION=$(grep GO_VERSION: /chezmoi/.github/workflows/main.yml | awk '{ print $2 }' ) + +go get "golang.org/dl/go${GO_VERSION}" +"${HOME}/go/bin/go${GO_VERSION}" download +export PATH="${HOME}/sdk/go${GO_VERSION}/bin:${PATH}" + +( cd /chezmoi && go test ./... ) diff --git a/internal/cmd/config_test.go b/internal/cmd/config_test.go index 09c268f39d9..f67c98c41e5 100644 --- a/internal/cmd/config_test.go +++ b/internal/cmd/config_test.go @@ -3,7 +3,6 @@ package cmd import ( "io" "io/fs" - "os" "path/filepath" "runtime" "testing" @@ -175,7 +174,7 @@ func newTestConfig(t *testing.T, fileSystem vfs.FS, options ...configOption) *Co withDestSystem(system), withSourceSystem(system), withTestFS(fileSystem), - withTestUser("user"), + withTestUser(t, "user"), withUmask(chezmoitest.Umask), }, options...)..., ) @@ -225,23 +224,22 @@ func withTestFS(fileSystem vfs.FS) configOption { } } -func withTestUser(username string) configOption { +func withTestUser(t *testing.T, username string) configOption { + t.Helper() return func(c *Config) error { var env string switch runtime.GOOS { case "plan9": - c.homeDir = "/home/user" + c.homeDir = filepath.Join("/", "home", username) env = "home" case "windows": - c.homeDir = `c:\home\user` + c.homeDir = filepath.Join("C:\\", "home", username) env = "USERPROFILE" default: - c.homeDir = "/home/user" + c.homeDir = filepath.Join("/", "home", username) env = "HOME" } - if err := os.Setenv(env, c.homeDir); err != nil { - panic(err) - } + t.Setenv(env, c.homeDir) var err error c.homeDirAbsPath, err = chezmoi.NormalizePath(c.homeDir) if err != nil { diff --git a/internal/cmd/testdata/scripts/workingtree.txt b/internal/cmd/testdata/scripts/workingtree.txt index dae594cd4d4..45473928f5f 100644 --- a/internal/cmd/testdata/scripts/workingtree.txt +++ b/internal/cmd/testdata/scripts/workingtree.txt @@ -1,3 +1,5 @@ +[!exec:true] skip 'true not found in $PATH' + mkhomedir # test that chezmoi cd creates the working tree if needed @@ -12,6 +14,13 @@ cp golden/.file $CHEZMOISOURCEDIR/home/dot_file chhome home2/user +# test chezmoi init --working-tree creates the correct directory +chezmoi init --working-tree=$HOME${/}.dotfiles --source=$HOME${/}.dotfiles${/}home +exists $HOME/.dotfiles/.git +exists $HOME/.dotfiles/home + +chhome home3/user + # test that chezmoi add returns an error if the source directory is not in the working tree mkhomedir ! chezmoi add $HOME${/}.file @@ -27,6 +36,6 @@ workingTree = "~/.local/share/chezmoi" sourceDir = "~/.local/share/chezmoi/home" [cd] command = "true" --- home2/user/.config/chezmoi/chezmoi.toml -- +-- home3/user/.config/chezmoi/chezmoi.toml -- workingTree = "~/.local/share/chezmoi/home" sourceDir = "~/.local/share/chezmoi"