From 778a31558089e6dbf8ed8dfd61fc1b4cbb2c4526 Mon Sep 17 00:00:00 2001 From: yunielrc87 Date: Sat, 16 Sep 2023 14:41:40 -0400 Subject: [PATCH] fix(package): execute instruction only if file type match --- .../package/ydf-package-service.bash | 12 ++++++++-- tests/fixtures/packages/0freedom-fail/homeln | 0 .../package/ydf-package-command.f.bats | 20 ++++++++++++++++- .../package/ydf-package-service.i.bats | 22 +++++++++++++++---- 4 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 tests/fixtures/packages/0freedom-fail/homeln diff --git a/src/usr/lib/ydf/components/package/ydf-package-service.bash b/src/usr/lib/ydf/components/package/ydf-package-service.bash index a3bad1f..57b1235 100644 --- a/src/usr/lib/ydf/components/package/ydf-package-service.bash +++ b/src/usr/lib/ydf/components/package/ydf-package-service.bash @@ -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}" @@ -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 diff --git a/tests/fixtures/packages/0freedom-fail/homeln b/tests/fixtures/packages/0freedom-fail/homeln new file mode 100644 index 0000000..e69de29 diff --git a/tests/usr/lib/ydf/components/package/ydf-package-command.f.bats b/tests/usr/lib/ydf/components/package/ydf-package-command.f.bats index 2a50b33..b5b02dd 100644 --- a/tests/usr/lib/ydf/components/package/ydf-package-command.f.bats +++ b/tests/usr/lib/ydf/components/package/ydf-package-command.f.bats @@ -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" @@ -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 +} diff --git a/tests/usr/lib/ydf/components/package/ydf-package-service.i.bats b/tests/usr/lib/ydf/components/package/ydf-package-service.i.bats index 90dd48b..6f0d7aa 100644 --- a/tests/usr/lib/ydf/components/package/ydf-package-service.i.bats +++ b/tests/usr/lib/ydf/components/package/ydf-package-service.i.bats @@ -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" { @@ -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" @@ -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 }