Skip to content

Commit

Permalink
chore: Minor test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Oct 2, 2021
1 parent 57ff617 commit 80efab9
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
3 changes: 2 additions & 1 deletion assets/docker/fedora.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions assets/docker/fedora.entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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 ./... )
16 changes: 7 additions & 9 deletions internal/cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"io"
"io/fs"
"os"
"path/filepath"
"runtime"
"testing"
Expand Down Expand Up @@ -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...)...,
)
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 10 additions & 1 deletion internal/cmd/testdata/scripts/workingtree.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[!exec:true] skip 'true not found in $PATH'

mkhomedir

# test that chezmoi cd creates the working tree if needed
Expand All @@ -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
Expand All @@ -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"

0 comments on commit 80efab9

Please sign in to comment.