Skip to content

Commit

Permalink
Testing accounts for marked file cache (#4)
Browse files Browse the repository at this point in the history
* Account for mark file in testing.

* Remove some debugging and tests back

* Add back tests?
  • Loading branch information
naturedamends authored Aug 11, 2023
1 parent 7b347b4 commit 99de406
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 35 deletions.
44 changes: 23 additions & 21 deletions src/common-utils/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -452,40 +452,42 @@ if [ "${INSTALL_ZSH}" = "true" ]; then

# Adapted, simplified inline Oh My Zsh! install steps that adds, defaults to a codespaces theme.
# See https://github.com/ohmyzsh/ohmyzsh/blob/master/tools/install.sh for official script.
oh_my_install_dir="${user_home}/.oh-my-zsh"
if [ ! -d "${oh_my_install_dir}" ] && [ "${INSTALL_OH_MY_ZSH}" = "true" ]; then
template_path="${oh_my_install_dir}/templates/zshrc.zsh-template"
if [ "${INSTALL_OH_MY_ZSH}" = "true" ]; then
user_rc_file="${user_home}/.zshrc"
umask g-w,o-w
mkdir -p ${oh_my_install_dir}
git clone --depth=1 \
-c core.eol=lf \
-c core.autocrlf=false \
-c fsck.zeroPaddedFilemode=ignore \
-c fetch.fsck.zeroPaddedFilemode=ignore \
-c receive.fsck.zeroPaddedFilemode=ignore \
"https://github.com/ohmyzsh/ohmyzsh" "${oh_my_install_dir}" 2>&1
oh_my_install_dir="${user_home}/.oh-my-zsh"
template_path="${oh_my_install_dir}/templates/zshrc.zsh-template"
if [ ! -d "${oh_my_install_dir}" ]; then
umask g-w,o-w
mkdir -p ${oh_my_install_dir}
git clone --depth=1 \
-c core.eol=lf \
-c core.autocrlf=false \
-c fsck.zeroPaddedFilemode=ignore \
-c fetch.fsck.zeroPaddedFilemode=ignore \
-c receive.fsck.zeroPaddedFilemode=ignore \
"https://github.com/ohmyzsh/ohmyzsh" "${oh_my_install_dir}" 2>&1

# Shrink git while still enabling updates
cd "${oh_my_install_dir}"
git repack -a -d -f --depth=1 --window=1
fi

# Add Dev Containers theme
mkdir -p ${oh_my_install_dir}/custom/themes
cp -f "${FEATURE_DIR}/scripts/devcontainers.zsh-theme" "${oh_my_install_dir}/custom/themes/devcontainers.zsh-theme"
ln -s "${oh_my_install_dir}/custom/themes/devcontainers.zsh-theme" "${oh_my_install_dir}/custom/themes/codespaces.zsh-theme"
ln -sf "${oh_my_install_dir}/custom/themes/devcontainers.zsh-theme" "${oh_my_install_dir}/custom/themes/codespaces.zsh-theme"

# Attempt adding devcontainer .zshrc template
# Add devcontainer .zshrc template
if [ "$INSTALL_OH_MY_ZSH_CONFIG" = "true" ]; then
echo -e "$(cat "${template_path}")\nDISABLE_AUTO_UPDATE=true\nDISABLE_UPDATE_PROMPT=true" > ${user_rc_file}
sed -i -e 's/ZSH_THEME=.*/ZSH_THEME="devcontainers"/g' ${user_rc_file}
fi

# Shrink git while still enabling updates
cd "${oh_my_install_dir}"
git repack -a -d -f --depth=1 --window=1

# Copy to non-root user if one is specified
if [ "${USERNAME}" != "root" ]; then
copy_to_root_files=("${oh_my_install_dir}")
[ -f "$user_rc_file" ] && copy_to_root_files+=("$user_rc_file")
cp -rf "${copy_to_root_files[@]}" /root
copy_to_user_files=("${oh_my_install_dir}")
[ -f "$user_rc_file" ] && copy_to_user_files+=("$user_rc_file")
cp -rf "${copy_to_user_files[@]}" /root
chown -R ${USERNAME}:${group_name} "${oh_my_install_dir}" "${user_rc_file}"
fi
fi
Expand Down
2 changes: 1 addition & 1 deletion test/common-utils/configure_zsh_as_default_shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ source dev-container-features-test-lib
# Definition specific tests
check "default-shell-is-zsh" bash -c "getent passwd $(whoami) | awk -F: '{ print $7 }' | grep '/bin/zsh'"
# check it overrides the ~/.zshrc with default dev containers template
check "default-zshrc-is-dev-container-template" bash -c "cat ~/.zshrc | grep ZSH_THEME=\"devcontainers\""
check "default-zshrc-is-dev-container-template" bash -c "cat ~/.zshrc | grep ZSH_THEME | grep devcontainers"

# Report result
reportResults
12 changes: 0 additions & 12 deletions test/common-utils/configure_zsh_as_default_shell_no_template.sh

This file was deleted.

16 changes: 16 additions & 0 deletions test/common-utils/configure_zsh_no_template.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -e

# Optional: Import test library
source dev-container-features-test-lib

# Definition specific tests
function file_not_overridden() {
cat /home/natured.log
cat ~/.zshrc | grep 'alias fnomockalias=' | grep testingmock
}
check "default-zsh-with-no-zshrc" file_not_overridden

# Report result
reportResults
5 changes: 4 additions & 1 deletion test/common-utils/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,13 @@
}
}
},
"configure_zsh_as_default_shell_no_template": {
"configure_zsh_no_template": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"postCreateCommand": "echo alias fnomockalias=testingmock >> /root/.zshrc",
"remoteUser": "root",
"features": {
"common-utils": {
"installZsh": true,
"installOhMyZshConfig": false
}
}
Expand Down

0 comments on commit 99de406

Please sign in to comment.