Skip to content

Commit

Permalink
fix(package): execute instruction only if file type match
Browse files Browse the repository at this point in the history
  • Loading branch information
yunielrc committed Sep 16, 2023
1 parent ed4a268 commit 778a315
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
12 changes: 10 additions & 2 deletions src/usr/lib/ydf/components/package/ydf-package-service.bash
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ fi
# readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_MANJARO="preinstall pacman yay install postinstall ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}"
# readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_UBUNTU="preinstall apt install postinstall ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}"
# shellcheck disable=SC2016
readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON='install @flatpak @snap docker_compose:docker-compose.yml plugin_zsh:${pkg_name}.plugin.zsh homeln postinstall'
readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON='install @flatpak @snap docker_compose:docker-compose.yml plugin_zsh:${pkg_name}.plugin.zsh homeln/ postinstall'

readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_MANJARO="preinstall @pacman @yay ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}"
# readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_UBUNTU="preinstall install postinstall ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}"

Expand Down Expand Up @@ -287,10 +288,17 @@ ydf::package_service::install_one_from_dir() {
for _instr in "${instr_arr[@]}"; do

local ifunc_partial_name="${_instr%%:*}"
ifunc_partial_name="${ifunc_partial_name%/}"
eval local ifile_name="${_instr##*:}"

local ifunction="ydf::package_service::__instruction_${ifunc_partial_name}"

# shellcheck disable=SC2154
if [[ ! -f "./${ifile_name}" ]]; then
if [[ "$ifile_name" == */ ]]; then
if [[ ! -d "./${ifile_name}" ]]; then
continue
fi
elif [[ ! -f "./${ifile_name}" ]]; then
continue
fi

Expand Down
Empty file.
20 changes: 19 additions & 1 deletion tests/usr/lib/ydf/components/package/ydf-package-command.f.bats
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ com.github.tchx84.Flatseal: postinstall succeed"
assert [ -n "$output" ]
}

# Tests for ydf package install
# Tests for ydf package install ./10ydfplugin
@test "ydf package install ./10ydfplugin Should succeed" {
local -r _package_dir="${TEST_FIXTURES_DIR}/packages/10ydfplugin"

Expand All @@ -293,3 +293,21 @@ com.github.tchx84.Flatseal: postinstall succeed"
assert_success
assert_output "YZSH_PLUGINS+=(10ydfplugin)"
}

# Tests for ydf package install ./11homeln
@test "ydf package install ./11homeln Should succeed" {
local -r _package_dir="${TEST_FIXTURES_DIR}/packages/11homeln"

run ydf package install "$_package_dir"

assert_success
assert_output "'/home/vedv/.my' -> '/home/vedv/ydf/tests/fixtures/packages/11homeln/homeln/.my'
'/home/vedv/.my-config.env' -> '/home/vedv/ydf/tests/fixtures/packages/11homeln/homeln/.my-config.env'"

assert [ -L '/home/vedv/.my' ]
assert [ -d '/home/vedv/.my' ]
assert [ -L '/home/vedv/.my-config.env' ]
assert [ -f '/home/vedv/.my-config.env' ]

rm /home/vedv/.my /home/vedv/.my-config.env
}
22 changes: 18 additions & 4 deletions tests/usr/lib/ydf/components/package/ydf-package-service.i.bats
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,33 @@ setup() {
ydf::package_service::get_instructions_names() {
assert_equal "$*" ''

echo 'instruction1 preinstall'
echo 'docker_compose:docker-compose.yml instruction1 preinstall homeln/ install'
}
ydf::package_service::__instruction_docker_compose() {
assert_equal "$*" '0freedom-fail'
echo docker_compose
}
ydf::package_service::__instruction_instruction1() {
assert_equal "$*" '0freedom-fail'
echo instruction1
}

ydf::package_service::__instruction_preinstall() {
assert_equal "$*" '0freedom-fail'
echo preinstall
}

ydf::package_service::__instruction_homeln() {
assert_equal "$*" '0freedom-fail'
echo homeln
}
ydf::package_service::__instruction_install() {
assert_equal "$*" '0freedom-fail'
echo install
}
run ydf::package_service::install_one_from_dir "$_package_dir"

assert_success
assert_output "preinstall"
assert_output "docker_compose
preinstall"
}

@test "ydf::package_service::install_one_from_dir() Should succeed if all instructions are success" {
Expand Down Expand Up @@ -339,6 +350,7 @@ docker_compose"
Plugin '10ydfplugin' already added to /home/vedv/.yzsh-gen.env"
}

# Tests for ydf::package_service::__instruction_homeln()
@test "ydf::package_service::__instruction_homeln() Should add plugin" {
cd "${TEST_FIXTURES_DIR}/packages/11homeln"

Expand All @@ -352,4 +364,6 @@ Plugin '10ydfplugin' already added to /home/vedv/.yzsh-gen.env"
assert [ -d '/home/vedv/.my' ]
assert [ -L '/home/vedv/.my-config.env' ]
assert [ -f '/home/vedv/.my-config.env' ]

rm /home/vedv/.my /home/vedv/.my-config.env
}

0 comments on commit 778a315

Please sign in to comment.