Skip to content

Commit

Permalink
feat(package): add instruction postinstall
Browse files Browse the repository at this point in the history
  • Loading branch information
yunielrc committed Sep 13, 2023
1 parent 3b374df commit 9cb6f27
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 3 deletions.
19 changes: 17 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 @@ -29,8 +29,8 @@ fi
# readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_UBUNTU="preinstall apt install postinstall ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}"

readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON=''
readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_MANJARO="preinstall install ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}"
readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_UBUNTU="preinstall install ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}"
readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_MANJARO="preinstall install postinstall ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}"
readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_UBUNTU="preinstall install postinstall ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}"

#
# FUNCTIONS
Expand Down Expand Up @@ -104,6 +104,21 @@ ydf::package_service::__instruction_install() {
bash ./install
}

#
# Execute preinstall script
#
#
# Returns:
# 0 on success, non-zero on error.
#
ydf::package_service::__instruction_postinstall() {
if [[ ! -f ./postinstall ]]; then
return 0
fi

bash ./postinstall
}

#
# Install a ydotfile package from a directory
#
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/packages/4postinstall/install
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo '4postinstall: install succeed'
1 change: 1 addition & 0 deletions tests/fixtures/packages/4postinstall/postinstall
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo '4postinstall: postinstall succeed'
1 change: 1 addition & 0 deletions tests/fixtures/packages/4postinstall/preinstall
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo '4postinstall: preinstall succeed'
14 changes: 13 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 @@ -77,7 +77,7 @@ ydf package COMMAND'

# Tests for ydf package install ../3install
@test "ydf package install --os manjaro ../3install, Should succeed With no install script" {
local -r _package_dir="${TEST_FIXTURES_DIR}/packages"
local -r _package_dir="${TEST_FIXTURES_DIR}/packages/0empty"

run ydf package install --os manjaro "$_package_dir"

Expand All @@ -94,3 +94,15 @@ ydf package COMMAND'
assert_output "3install: preinstall succeed
3install: install succeed"
}

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

run ydf package install "$_package_dir"

assert_success
assert_output "4postinstall: preinstall succeed
4postinstall: install succeed
4postinstall: postinstall succeed"
}
11 changes: 11 additions & 0 deletions tests/usr/lib/ydf/components/package/ydf-package-service.bats
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,14 @@ preinstall"
assert_success
assert_output "3install: install succeed"
}

# Tests for ydf::package_service::__instruction_postinstall()
@test "ydf::package_service::__instruction_postinstall() Should succeed" {

cd "${TEST_FIXTURES_DIR}/packages/4postinstall"

run ydf::package_service::__instruction_postinstall

assert_success
assert_output "4postinstall: postinstall succeed"
}

0 comments on commit 9cb6f27

Please sign in to comment.