Skip to content

Commit

Permalink
Add more integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed May 12, 2020
1 parent 5aa228a commit f2f4561
Show file tree
Hide file tree
Showing 15 changed files with 379 additions and 56 deletions.
8 changes: 4 additions & 4 deletions testdata/scripts/applyremove.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
exists $HOME${/}.bashrc
exists $HOME${/}.inputrc
exists $HOME/.bashrc
exists $HOME/.inputrc
chezmoi apply --remove
! exists $HOME${/}.bashrc
exists $HOME${/}.inputrc
! exists $HOME/.bashrc
exists $HOME/.inputrc

-- home/user/.bashrc --
# contents of .bashrc
Expand Down
26 changes: 25 additions & 1 deletion testdata/scripts/cat.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
chezmoi cat $HOME${/}.bashrc
stdout '# contents of .bashrc'
cmp stdout ${CHEZMOISOURCEDIR}/dot_bashrc

chezmoi cat $HOME${/}.gitconfig
cmp stdout golden/.gitconfig

chezmoi cat $HOME${/}.symlink
stdout 'target'

! chezmoi cat $HOME${/}.ssh
stdout 'not a file or symlink'

-- golden/.gitconfig --
[user]
email = user@home.org
-- 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
-- home/user/.local/share/chezmoi/dot_gitconfig.tmpl --
[user]
email = {{ .email }}
-- home/user/.local/share/chezmoi/private_dot_ssh/config --
# contents of .ssh/config
-- home/user/.local/share/chezmoi/symlink_dot_symlink --
target
2 changes: 1 addition & 1 deletion testdata/scripts/cd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ grep -count=1 ${CHEZMOISOURCEDIR@R} shell.log

# test chezmoi cd with command with args
[!exec:bash] stop
chhome home2${/}user
chhome home2/user
chezmoi cd
stdout version

Expand Down
12 changes: 6 additions & 6 deletions testdata/scripts/chattr.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
chezmoi chattr +empty $HOME${/}.bashrc
exists ${CHEZMOISOURCEDIR}${/}empty_dot_bashrc
exists ${CHEZMOISOURCEDIR}/empty_dot_bashrc

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

chezmoi chattr +private $HOME${/}.bashrc
exists ${CHEZMOISOURCEDIR}${/}private_empty_dot_bashrc.tmpl
exists ${CHEZMOISOURCEDIR}/private_empty_dot_bashrc.tmpl

chezmoi chattr noempty $HOME${/}.bashrc
exists ${CHEZMOISOURCEDIR}${/}private_dot_bashrc.tmpl
exists ${CHEZMOISOURCEDIR}/private_dot_bashrc.tmpl

chezmoi chattr -- -template $HOME${/}.bashrc
exists ${CHEZMOISOURCEDIR}${/}private_dot_bashrc
exists ${CHEZMOISOURCEDIR}/private_dot_bashrc

chezmoi chattr nop $HOME${/}.bashrc
exists ${CHEZMOISOURCEDIR}${/}dot_bashrc
exists ${CHEZMOISOURCEDIR}/dot_bashrc

-- home/user/.local/share/chezmoi/dot_bashrc --
# contents of .bashrc
11 changes: 11 additions & 0 deletions testdata/scripts/completion.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
chezmoi completion bash
stdout '# bash completion for chezmoi'

chezmoi completion fish
stdout '# fish completion for chezmoi'

chezmoi completion zsh
stdout '#compdef _chezmoi chezmoi'

! chezmoi completion ksh
stdout 'unsupported shell'
11 changes: 11 additions & 0 deletions testdata/scripts/data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
chezmoi data
stdout '"chezmoi":'

chezmoi data --format=json
stdout '"chezmoi":'

chezmoi data --format=toml
stdout '[chezmoi]'

chezmoi data --format=yaml
stdout 'chezmoi:'
85 changes: 85 additions & 0 deletions testdata/scripts/diff.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
chmod 700 $HOME/.ssh

# test that chezmoi diff generates no output when the source and destination states are equal
chezmoi diff
! stdout .

# test that chezmoi diff generates a diff when a file is added to the source state
cp golden/dot_inputrc ${CHEZMOISOURCEDIR}/dot_inputrc
chezmoi diff
cmpenv stdout golden/add-file-diff
rm ${CHEZMOISOURCEDIR}/dot_inputrc

# test that chezmoi diff generates a diff when a file is edited
edit $HOME/.bashrc
chezmoi diff
cmpenv stdout golden/modify-file-diff
chezmoi apply

# test that chezmoi diff generates a diff when a file is removed from the destination directory
rm $HOME/.bashrc
chezmoi diff
cmpenv stdout golden/remove-file-diff
chezmoi apply

# test that chezmoi diff generates a diff when a directory is removed from the destination directory
rm $HOME/.ssh
chezmoi diff
cmpenv stdout golden/remove-dir-diff
chezmoi apply

[windows] stop 'remaining tests use POSIX file modes'

# test that chezmoi diff generates a diff when a file's permissions are changed
chmod 755 $HOME/.bashrc
chezmoi diff
cmpenv stdout golden/chmod-file-diff
chezmoi apply

# test that chezmoi diff generates a diff when a dir's permissions are changed
# FIXME show changes to permissions in diff
chmod 755 $HOME/.ssh
chezmoi diff
cmpenv stdout golden/chmod-dir-diff
chezmoi apply

-- golden/add-file-diff --
install -m 644 /dev/null $WORK/home/user/.inputrc
--- a$WORK/home/user/.inputrc
+++ b$WORK/home/user/.inputrc
@@ -0,0 +1,1 @@
+# contents of .inputrc
-- golden/modify-file-diff --
install -m 644 /dev/null $WORK/home/user/.bashrc
--- a$WORK/home/user/.bashrc
+++ b$WORK/home/user/.bashrc
@@ -1,2 +1,1 @@
# contents of .bashrc
-# edited
-- golden/remove-file-diff --
install -m 644 /dev/null $WORK/home/user/.bashrc
--- a$WORK/home/user/.bashrc
+++ b$WORK/home/user/.bashrc
@@ -0,0 +1,1 @@
+# contents of .bashrc
-- golden/remove-dir-diff --
mkdir -m 700 $WORK/home/user/.ssh
install -m 644 /dev/null $WORK/home/user/.ssh/config
--- a$WORK/home/user/.ssh/config
+++ b$WORK/home/user/.ssh/config
@@ -0,0 +1,1 @@
+# contents of .ssh/config
-- golden/chmod-file-diff --
chmod 644 $WORK/home/user/.bashrc
-- golden/chmod-dir-diff --
chmod 700 $WORK/home/user/.ssh
-- golden/dot_inputrc --
# contents of .inputrc
-- home/user/.bashrc --
# contents of .bashrc
-- home/user/.ssh/config --
# contents of .ssh/config
-- home/user/.local/share/chezmoi/dot_bashrc --
# contents of .bashrc
-- home/user/.local/share/chezmoi/private_dot_ssh/config --
# contents of .ssh/config
125 changes: 125 additions & 0 deletions testdata/scripts/dump.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
chezmoi --format=json dump
cmpenv stdout golden/dump.json

chezmoi --format=json dump $HOME${/}.bashrc
cmpenv stdout golden/dump-bashrc.json

chezmoi --format=json dump $HOME${/}.ssh
cmpenv stdout golden/dump-ssh.json

chezmoi --format=json --recursive=false dump $HOME${/}.ssh
cmpenv stdout golden/dump-ssh-non-recursive.json

chezmoi --format=yaml dump
cmpenv stdout golden/dump.yaml

! chezmoi dump $HOME${/}.inputrc
stdout 'file does not exist'

-- golden/dump.json --
[
{
"type": "file",
"sourcePath": "$WORK/home/user/.local/share/chezmoi/dot_bashrc",
"targetPath": ".bashrc",
"empty": false,
"encrypted": false,
"perm": 420,
"template": false,
"contents": "# contents of .bashrc\n"
},
{
"type": "dir",
"sourcePath": "$WORK/home/user/.local/share/chezmoi/private_dot_ssh",
"targetPath": ".ssh",
"exact": false,
"perm": 448,
"entries": [
{
"type": "file",
"sourcePath": "$WORK/home/user/.local/share/chezmoi/private_dot_ssh/config",
"targetPath": ".ssh/config",
"empty": false,
"encrypted": false,
"perm": 420,
"template": false,
"contents": "# contents of .ssh/config\n"
}
]
}
]
-- golden/dump-bashrc.json --
[
{
"type": "file",
"sourcePath": "$WORK/home/user/.local/share/chezmoi/dot_bashrc",
"targetPath": ".bashrc",
"empty": false,
"encrypted": false,
"perm": 420,
"template": false,
"contents": "# contents of .bashrc\n"
}
]
-- golden/dump-ssh.json --
[
{
"type": "dir",
"sourcePath": "$WORK/home/user/.local/share/chezmoi/private_dot_ssh",
"targetPath": ".ssh",
"exact": false,
"perm": 448,
"entries": [
{
"type": "file",
"sourcePath": "$WORK/home/user/.local/share/chezmoi/private_dot_ssh/config",
"targetPath": ".ssh/config",
"empty": false,
"encrypted": false,
"perm": 420,
"template": false,
"contents": "# contents of .ssh/config\n"
}
]
}
]
-- golden/dump-ssh-non-recursive.json --
[
{
"type": "dir",
"sourcePath": "$WORK/home/user/.local/share/chezmoi/private_dot_ssh",
"targetPath": ".ssh",
"exact": false,
"perm": 448,
"entries": null
}
]
-- golden/dump.yaml --
- type: file
sourcePath: $WORK/home/user/.local/share/chezmoi/dot_bashrc
targetPath: .bashrc
empty: false
encrypted: false
perm: 420
template: false
contents: |
# contents of .bashrc
- type: dir
sourcePath: $WORK/home/user/.local/share/chezmoi/private_dot_ssh
targetPath: .ssh
exact: false
perm: 448
entries:
- type: file
sourcePath: $WORK/home/user/.local/share/chezmoi/private_dot_ssh/config
targetPath: .ssh/config
empty: false
encrypted: false
perm: 420
template: false
contents: |
# contents of .ssh/config
-- home/user/.local/share/chezmoi/dot_bashrc --
# contents of .bashrc
-- home/user/.local/share/chezmoi/private_dot_ssh/config --
# contents of .ssh/config
12 changes: 6 additions & 6 deletions testdata/scripts/editconfig.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# test that edit-config creates a config file if needed
chezmoi edit-config
grep -count=1 '# edited' ${CHEZMOICONFIGDIR}${/}chezmoi.toml
grep -count=1 '# edited' ${CHEZMOICONFIGDIR}/chezmoi.toml

# test that edit-config edits an existing config file
chezmoi edit-config
grep -count=2 '# edited' ${CHEZMOICONFIGDIR}${/}chezmoi.toml
grep -count=2 '# edited' ${CHEZMOICONFIGDIR}/chezmoi.toml

# test that edit-config edits an existing YAML config file
chhome home2${/}user
chhome home2/user
chezmoi edit-config
grep -count=1 '# edited' $HOME${/}.config${/}chezmoi${/}chezmoi.yaml
grep -count=1 '# edited' $HOME/.config/chezmoi/chezmoi.yaml

# test that edit-config reports a warning if the config is no longer valid
chhome home3${/}user
chhome home3/user
chezmoi verify
! stderr warning
chezmoi edit-config
stderr warning
grep -count=1 '# edited' $HOME${/}.config${/}chezmoi${/}chezmoi.json
grep -count=1 '# edited' $HOME/.config/chezmoi/chezmoi.json

-- home2/user/.config/chezmoi/chezmoi.yaml --
data:
Expand Down
12 changes: 6 additions & 6 deletions testdata/scripts/forget.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
edit ${CHEZMOISOURCEDIR}/dot_bashrc
grep -count=1 '# edited' ${CHEZMOISOURCEDIR}${/}dot_bashrc
grep -count=1 '# edited' ${CHEZMOISOURCEDIR}/dot_bashrc

chezmoi apply
grep -count=1 '# edited' $HOME${/}.bashrc
grep -count=1 '# edited' $HOME/.bashrc

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

chezmoi forget $HOME${/}.bashrc
! exists ${CHEZMOISOURCEDIR}${/}dot_bashrc
! exists ${CHEZMOISOURCEDIR}/dot_bashrc

chezmoi apply
grep -count=1 '# edited' $HOME${/}.bashrc
grep -count=1 '# edited' $HOME/.bashrc

-- home/user/.local/share/chezmoi/dot_bashrc --
# contents of .bashrc
Loading

0 comments on commit f2f4561

Please sign in to comment.