Skip to content

Commit

Permalink
Test for file existence (#233)
Browse files Browse the repository at this point in the history
* add tests

* update files

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update
  • Loading branch information
shunk031 authored May 19, 2024
1 parent a55434c commit aedc22f
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .github/workflows/macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,12 @@ jobs:
alert-threshold: "150%"
alert-comment-cc-users: "@shunk031"
benchmark-data-dir-path: "."

- name: Test file existence
run: |
brew install bats-core
cd $(chezmoi source-path)/../
bats --print-output-on-failure \
tests/files/common.bats \
tests/files/macos.bats
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Run unit test
run: |
./scripts/run_test.sh
./scripts/run_unit_test.sh
- name: Set flag for codecov
run: |
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/ubuntu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,21 @@ jobs:
# │ │
# │ └─ Simulate inputting an system arcitecture into the config.
# └─ Simulate inputting an email address into the config.
- name: Install latest bats-core
run: |
tmp_dir=$(mktemp -d /tmp/bats-core-XXXXX)
git clone --depth 1 https://github.com/bats-core/bats-core.git "${tmp_dir}"
cd "${tmp_dir}"
sudo ./install.sh /usr/local
rm -rf "${tmp_dir}"
- name: Test file existence
env:
SYSTEM: ${{ matrix.system }}
run: |
cd $(chezmoi source-path)/../
bats tests/files/common.bats
bats --filter-tags common,ubuntu:${SYSTEM} \
--print-output-on-failure \
tests/files/ubuntu.bats
1 change: 1 addition & 0 deletions home/.chezmoitemplates/chezmoiignore.d/macos
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.profile
.bashrc
.tmux.conf.d/os/ubuntu_client.conf
.tmux.conf.d/system/server.conf
.config/sheldon/plugins.toml

Expand Down
File renamed without changes.
41 changes: 41 additions & 0 deletions tests/files/common.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bats

# bats file_tags=common
@test "[common] dotfiles" {
files_exists=(
"${HOME}/.config/git/ignore"
"${HOME}/.config/git/config"
"${HOME}/.config/jupyter/lab/user-settings/@jupyterlab/terminal-extension/plugin.jupyterlab-settings.json"
"${HOME}/.config/tango.yml"
"${HOME}/.local/bin/common/dev"
"${HOME}/.local/bin/common/gpg.sh"
"${HOME}/.local/bin/common/setup-gh"
"${HOME}/.gnupg/gpg-agent.conf"
"${HOME}/.ssh/config"
"${HOME}/.vimrc"
"${HOME}/.tmux.conf"
)
for file in "${files_exists[@]}"; do
echo "Checking ${file}"
[ -f "${file}" ]
done

directories_exists=(
"${HOME}/.config/fzf"
"${HOME}/.spacemacs.d"
"${HOME}/.pyenv"
)
for directory in "${directories_exists[@]}"; do
echo "Checking ${directory}"
[ -d "${directory}" ]
done

symbolic_links_exists=(
"${HOME}/.zshrc"
"${HOME}/.zprofile"
)
for link in "${symbolic_links_exists[@]}"; do
echo "Checking ${link}"
[ -L "${link}" ]
done
}
46 changes: 46 additions & 0 deletions tests/files/macos.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bats

@test "[macos] dotfiles" {
files_exists=(
"${HOME}/.config/powerlevel10k/p10k.zsh"
"${HOME}/.zsh/client/zshrc"
"${HOME}/.zsh/client/zprofile"
"${HOME}/.bash/client/bashrc"
"${HOME}/.tmux-powerlinerc"
"${HOME}/.tmux.conf.d/system/client.conf"
"${HOME}/.tmux.conf.d/os/macos.conf"
)
for file in "${files_exists[@]}"; do
echo "Checking ${file}"
[ -f "${file}" ]
done

directories_exists=(
"${HOME}/.local/bin/client"
"${HOME}/.zprezto"
)
for directory in "${directories_exists[@]}"; do
echo "Checking ${directory}"
[ -d "${directory}" ]
done

symbolic_links_exists=(
"${HOME}/Library/Application Support/iTerm2/DynamicProfiles/hotkey_window.json"
)
for link in "${symbolic_links_exists[@]}"; do
echo "Checking ${link}"
[ -L "${link}" ]
done

files_not_exists=(
"${HOME}/.local/bin/server"
"${HOME}/.zsh/server/zshrc"
"${HOME}/.zsh/server/zprofile"
"${HOME}/.tmux.conf.d/system/server.conf"
"${HOME}/.tmux.conf.d/os/ubuntu_client.conf"
)
for file in "${files_not_exists[@]}"; do
echo "Checking ${file}"
[ ! -f "${file}" ]
done
}
62 changes: 62 additions & 0 deletions tests/files/ubuntu.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env bats

# bats test_tags=ubuntu:client
@test "[ubuntu-client] dotfiles" {
files_exists=(
"${HOME}/.zsh/client/zshrc"
"${HOME}/.zsh/client/zprofile"
"${HOME}/.tmux-powerlinerc"
"${HOME}/.tmux.conf.d/system/client.conf"
"${HOME}/.tmux.conf.d/os/ubuntu_client.conf"
)
for file in "${files_exists[@]}"; do
echo "Checking ${file}"
[ -f "${file}" ]
done

directories_exists=(
"${HOME}/.local/bin/client"
"${HOME}/.zprezto"
)
for directory in "${directories_exists[@]}"; do
echo "Checking ${directory}"
[ -d "${directory}" ]
done

files_not_exists=(
"${HOME}/.zsh/server/zshrc"
"${HOME}/.zsh/server/zprofile"
"${HOME}/.tmux.conf.d/system/server.conf"
"${HOME}/.tmux.conf.d/os/macos.conf"
)
for file in "${files_not_exists[@]}"; do
echo "Checking ${file}"
[ ! -f "${file}" ]
done
}

# bats test_tags=ubuntu:server
@test "[ubuntu-server] dotfiles" {
files_exists=(
"${HOME}/.zsh/server/zshrc"
"${HOME}/.zsh/server/zprofile"
"${HOME}/.tmux.conf.d/system/server.conf"
"${HOME}/.tmux.conf.d/os/ubuntu_server.conf"
)
for file in "${files_exists[@]}"; do
echo "Checking ${file}"
[ -f "${file}" ]
done

files_not_exists=(
"${HOME}/.tmux-powerlinerc"
"${HOME}/.zsh/client/zshrc"
"${HOME}/.zsh/client/zprofile"
"${HOME}/.tmux.conf.d/system/client.conf"
"${HOME}/.tmux.conf.d/os/macos.conf"
)
for file in "${files_not_exists[@]}"; do
echo "Checking ${file}"
[ ! -f "${file}" ]
done
}

1 comment on commit aedc22f

@shunk031
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'MacOS benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.

Benchmark suite Current: aedc22f Previous: d730987 Ratio
zsh average startup time 0.299 Second 0.132 Second 2.27
zsh initial startup time 1.27 Second 0.75 Second 1.69

This comment was automatically generated by workflow using github-action-benchmark.

CC: @shunk031

Please sign in to comment.