Skip to content

Commit

Permalink
Merge pull request #744 from twpayne/test-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed May 11, 2020
2 parents 89d9dc7 + 7e4266e commit 3cee752
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GOLANGCI_LINT_VERSION=1.25.0
GOLANGCI_LINT_VERSION=1.26.0

.PHONY: default
default: generate run test lint format
Expand Down
14 changes: 14 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func edit(ts *testscript.TestScript, neg bool, args []string) {
ts.Fatalf("edit: %v", err)
}
data = append(data, []byte("# edited\n")...)
//nolint:gosec
if err := ioutil.WriteFile(filename, data, 0o666); err != nil {
ts.Fatalf("edit: %v", err)
}
Expand Down Expand Up @@ -115,6 +116,19 @@ func setup(env *testscript.Env) error {
env.Setenv("SHELL", filepath.Join(binDir, "shell"))
}

// Fix permissions on the source directory, if it exists.
_ = os.Chmod(chezmoiSourceDir, 0o700)

// Fix permissions on any files in the bin directory.
infos, err := ioutil.ReadDir(binDir)
if err == nil {
for _, info := range infos {
if err := os.Chmod(filepath.Join(binDir, info.Name()), 0o755); err != nil {
return err
}
}
}

root := map[string]interface{}{
"/home/user": map[string]interface{}{
// .gitconfig is populated with a user and email to avoid warnings
Expand Down
2 changes: 0 additions & 2 deletions testdata/scripts/applyremove.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
chmod 700 ${CHEZMOISOURCEDIR}

exists $HOME${/}.bashrc
exists $HOME${/}.inputrc
chezmoi apply --remove
Expand Down
12 changes: 9 additions & 3 deletions testdata/scripts/archive.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
[windows] stop 'https://github.com/twpayne/chezmoi/issues/745'
[!exec:tar] stop

chezmoi add $HOME${/}.bashrc
chezmoi archive --output=user.tar
exec tar -tf user.tar
stdout ^\.bashrc\s*$
cmp stdout golden/archive

-- home/user/.bashrc --
-- golden/archive --
.bashrc
.ssh
.ssh/config
-- home/user/.local/share/chezmoi/dot_bashrc --
# contents of .bashrc
-- home/user/.local/share/chezmoi/private_dot_ssh/config --
# contents .ssh/config
5 changes: 1 addition & 4 deletions testdata/scripts/chattr.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
chezmoi add $HOME${/}.bashrc
exists ${CHEZMOISOURCEDIR}${/}dot_bashrc

chezmoi chattr +empty $HOME${/}.bashrc
exists ${CHEZMOISOURCEDIR}${/}empty_dot_bashrc

Expand All @@ -19,5 +16,5 @@ exists ${CHEZMOISOURCEDIR}${/}private_dot_bashrc
chezmoi chattr nop $HOME${/}.bashrc
exists ${CHEZMOISOURCEDIR}${/}dot_bashrc

-- home/user/.bashrc --
-- home/user/.local/share/chezmoi/dot_bashrc --
# contents of .bashrc
2 changes: 0 additions & 2 deletions testdata/scripts/executetemplate.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
chmod 700 ${CHEZMOISOURCEDIR}

chezmoi execute-template '{{ "output" }}'
stdout output

Expand Down
5 changes: 1 addition & 4 deletions testdata/scripts/forget.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
chezmoi add $HOME${/}.bashrc
cmp ${CHEZMOISOURCEDIR}${/}dot_bashrc $HOME${/}.bashrc

edit ${CHEZMOISOURCEDIR}/dot_bashrc
grep -count=1 '# edited' ${CHEZMOISOURCEDIR}${/}dot_bashrc

Expand All @@ -16,5 +13,5 @@ chezmoi forget $HOME${/}.bashrc
chezmoi apply
grep -count=1 '# edited' $HOME${/}.bashrc

-- home/user/.bashrc --
-- home/user/.local/share/chezmoi/dot_bashrc --
# contents of .bashrc
24 changes: 21 additions & 3 deletions testdata/scripts/managed.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
chezmoi add $HOME${/}.bashrc
[windows] stop 'https://github.com/twpayne/chezmoi/issues/745'

chezmoi managed
stdout '.bashrc'
cmpenv stdout golden/managed

chezmoi --include=dirs managed
cmpenv stdout golden/managed-dirs

chezmoi --include=files managed
cmpenv stdout golden/managed-files

-- home/user/.bashrc --
-- golden/managed --
$HOME/.bashrc
$HOME/.ssh
$HOME/.ssh/config
-- golden/managed-dirs --
$HOME/.ssh
-- golden/managed-files --
$HOME/.bashrc
$HOME/.ssh/config
-- home/user/.local/share/chezmoi/dot_bashrc --
# contents of .bashrc
-- home/user/.local/share/chezmoi/dot_ssh/config --
# contents of .ssh/config
7 changes: 2 additions & 5 deletions testdata/scripts/purge.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
chezmoi add $HOME${/}.bashrc
exists ${CHEZMOISOURCEDIR}${/}dot_bashrc

chezmoi purge --force
! exists ${CHEZMOICONFIGDIR}
! exists ${CHEZMOISOURCEDIR}

-- home/user/.bashrc --
# contents of .bashrc
-- home/user/.config/chezmoi/chezmoi.toml --
[data]
email = "user@home.org"
-- home/user/.local/share/chezmoi/dot_bashrc --
# contents of .bashrc
3 changes: 0 additions & 3 deletions testdata/scripts/secretgeneric.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
chmod 755 bin/secret
chmod 700 $HOME/.local/share/chezmoi

chezmoi secret generic examplepassword
stdout examplepassword

Expand Down
3 changes: 0 additions & 3 deletions testdata/scripts/secretgopass.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
chmod 755 bin/gopass
chmod 700 $HOME/.local/share/chezmoi

chezmoi -v secret gopass show misc/example.com
stdout examplepassword

Expand Down
6 changes: 3 additions & 3 deletions testdata/scripts/secretlastpass.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
chmod 755 bin/lpass
chmod 700 $HOME/.local/share/chezmoi

chezmoi secret lastpass -- show --json example.com
stdout examplelogin

Expand Down Expand Up @@ -55,6 +52,9 @@ IF "%*" == "--version" (
echo. "note": ""
echo. }
echo.]
) ELSE (
echo lpass: invalid command: %*
exit /b 1
)
-- home/user/.local/share/chezmoi/private_dot_netrc.tmpl --
machine example.com
Expand Down
3 changes: 0 additions & 3 deletions testdata/scripts/secretpass.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
chmod 755 bin/pass
chmod 700 $HOME/.local/share/chezmoi

chezmoi -v secret pass show misc/example.com
stdout examplepassword

Expand Down
2 changes: 0 additions & 2 deletions testdata/scripts/sourcepath.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
chezmoi init

chezmoi source-path
stdout ${CHEZMOISOURCEDIR@R}

Expand Down

0 comments on commit 3cee752

Please sign in to comment.