From dfe878d159121f959f61af2c08ac86c2f32ebca4 Mon Sep 17 00:00:00 2001 From: Castulo Martinez Date: Wed, 15 Aug 2018 16:36:46 -0700 Subject: [PATCH] Allow adding bundle dependency in newer versions With the current test library a user can create a test bundle and then add a dependency to that bundle by adding it to the bundle's manifest. However this only worked if there was only one version available in the web-server. A second issue was that after modifying the manifest the hash in the MoM would need to be updated. This commit allow users to create a version N, create a bundle for version N, then create a version N+M and add a dependency to that bundle in that new version N+M. It also recalculate all hashes in the MoM so users writing tests don't need to remember to update them themselves. Finally this commit includes some updates for some tests that use the add_dependency_to_manifest function since they don't need to update hashes in the MoM as a separate step any more. --- test/functional/bundleadd_v2/add-include.bats | 2 -- .../bundlelist_v2/list-deps-flat.bats | 1 - .../bundlelist_v2/list-deps-nested.bats | 1 - .../list-has-dep-nested-not-installed.bats | 1 - .../list-has-dep-nested-server.bats | 1 - .../bundlelist_v2/list-has-dep-nested.bats | 1 - .../remove-include-nested.bats | 1 - .../bundleremove_v2/remove-include.bats | 1 - test/functional/testlib.bash | 26 ++++++++++++++++--- 9 files changed, 22 insertions(+), 13 deletions(-) diff --git a/test/functional/bundleadd_v2/add-include.bats b/test/functional/bundleadd_v2/add-include.bats index 76d49088..20552902 100755 --- a/test/functional/bundleadd_v2/add-include.bats +++ b/test/functional/bundleadd_v2/add-include.bats @@ -9,8 +9,6 @@ test_setup() { create_bundle -n test-bundle2 -f /bar/test-file2 "$TEST_NAME" # add test-bundle2 as a dependency of test-bundle1 add_dependency_to_manifest "$TEST_NAME"/web-dir/10/Manifest.test-bundle1 test-bundle2 - # since we modified one manifest we need to update that in MoM too, so re add the bundle manifest - update_hashes_in_mom "$TEST_NAME"/web-dir/10/Manifest.MoM } diff --git a/test/functional/bundlelist_v2/list-deps-flat.bats b/test/functional/bundlelist_v2/list-deps-flat.bats index 1d390f6e..6a607371 100755 --- a/test/functional/bundlelist_v2/list-deps-flat.bats +++ b/test/functional/bundlelist_v2/list-deps-flat.bats @@ -11,7 +11,6 @@ test_setup() { # add bundle2 and 3 as dependencies of bundle1 add_dependency_to_manifest "$TEST_NAME"/web-dir/10/Manifest.test-bundle1 test-bundle2 add_dependency_to_manifest "$TEST_NAME"/web-dir/10/Manifest.test-bundle1 test-bundle3 - update_hashes_in_mom "$TEST_NAME"/web-dir/10/Manifest.MoM } diff --git a/test/functional/bundlelist_v2/list-deps-nested.bats b/test/functional/bundlelist_v2/list-deps-nested.bats index 0bbed34c..6970db35 100755 --- a/test/functional/bundlelist_v2/list-deps-nested.bats +++ b/test/functional/bundlelist_v2/list-deps-nested.bats @@ -11,7 +11,6 @@ test_setup() { # add bundle2 as dependencies of bundle1 and bundle 3 as dependency of bundle2 add_dependency_to_manifest "$TEST_NAME"/web-dir/10/Manifest.test-bundle1 test-bundle2 add_dependency_to_manifest "$TEST_NAME"/web-dir/10/Manifest.test-bundle2 test-bundle3 - update_hashes_in_mom "$TEST_NAME"/web-dir/10/Manifest.MoM } diff --git a/test/functional/bundlelist_v2/list-has-dep-nested-not-installed.bats b/test/functional/bundlelist_v2/list-has-dep-nested-not-installed.bats index 168a1680..264373cb 100755 --- a/test/functional/bundlelist_v2/list-has-dep-nested-not-installed.bats +++ b/test/functional/bundlelist_v2/list-has-dep-nested-not-installed.bats @@ -11,7 +11,6 @@ test_setup() { # add bundle1 as dependencies of bundle2 and bundle 2 as dependency of bundle3 add_dependency_to_manifest "$TEST_NAME"/web-dir/10/Manifest.test-bundle2 test-bundle1 add_dependency_to_manifest "$TEST_NAME"/web-dir/10/Manifest.test-bundle3 test-bundle2 - update_hashes_in_mom "$TEST_NAME"/web-dir/10/Manifest.MoM } diff --git a/test/functional/bundlelist_v2/list-has-dep-nested-server.bats b/test/functional/bundlelist_v2/list-has-dep-nested-server.bats index cbcb8c33..1e381783 100755 --- a/test/functional/bundlelist_v2/list-has-dep-nested-server.bats +++ b/test/functional/bundlelist_v2/list-has-dep-nested-server.bats @@ -11,7 +11,6 @@ test_setup() { # add bundle1 as dependencies of bundle2 and bundle 2 as dependency of bundle3 add_dependency_to_manifest "$TEST_NAME"/web-dir/10/Manifest.test-bundle2 test-bundle1 add_dependency_to_manifest "$TEST_NAME"/web-dir/10/Manifest.test-bundle3 test-bundle2 - update_hashes_in_mom "$TEST_NAME"/web-dir/10/Manifest.MoM } diff --git a/test/functional/bundlelist_v2/list-has-dep-nested.bats b/test/functional/bundlelist_v2/list-has-dep-nested.bats index 2bffa0b0..0f8ef271 100755 --- a/test/functional/bundlelist_v2/list-has-dep-nested.bats +++ b/test/functional/bundlelist_v2/list-has-dep-nested.bats @@ -11,7 +11,6 @@ test_setup() { # add bundle1 as dependencies of bundle2 and bundle 2 as dependency of bundle3 add_dependency_to_manifest "$TEST_NAME"/web-dir/10/Manifest.test-bundle2 test-bundle1 add_dependency_to_manifest "$TEST_NAME"/web-dir/10/Manifest.test-bundle3 test-bundle2 - update_hashes_in_mom "$TEST_NAME"/web-dir/10/Manifest.MoM } diff --git a/test/functional/bundleremove_v2/remove-include-nested.bats b/test/functional/bundleremove_v2/remove-include-nested.bats index 360db37a..e73688f5 100755 --- a/test/functional/bundleremove_v2/remove-include-nested.bats +++ b/test/functional/bundleremove_v2/remove-include-nested.bats @@ -11,7 +11,6 @@ test_setup() { # add dependencies add_dependency_to_manifest "$TEST_NAME"/web-dir/10/Manifest.test-bundle2 test-bundle1 add_dependency_to_manifest "$TEST_NAME"/web-dir/10/Manifest.test-bundle3 test-bundle2 - update_hashes_in_mom "$TEST_NAME"/web-dir/10/Manifest.MoM } diff --git a/test/functional/bundleremove_v2/remove-include.bats b/test/functional/bundleremove_v2/remove-include.bats index 85c5f4ce..9fe22565 100755 --- a/test/functional/bundleremove_v2/remove-include.bats +++ b/test/functional/bundleremove_v2/remove-include.bats @@ -9,7 +9,6 @@ test_setup() { create_bundle -L -n test-bundle2 -f /bar/test-file2 "$TEST_NAME" # add test-bundle1 as dependency of test-bundle2 add_dependency_to_manifest "$TEST_NAME"/web-dir/10/Manifest.test-bundle2 test-bundle1 - update_hashes_in_mom "$TEST_NAME"/web-dir/10/Manifest.MoM } diff --git a/test/functional/testlib.bash b/test/functional/testlib.bash index c48433aa..1def2430 100644 --- a/test/functional/testlib.bash +++ b/test/functional/testlib.bash @@ -450,7 +450,8 @@ add_dependency_to_manifest() { local dependency=$2 local path local manifest_name - local bundle_name + local version + local pre_version # If no parameters are received show usage if [ $# -eq 0 ]; then cat <<-EOM @@ -460,14 +461,31 @@ add_dependency_to_manifest() { return fi validate_item "$manifest" - path=$(dirname "$manifest") - manifest_name=$(basename "$manifest") - bundle_name=${manifest_name#Manifest.} + validate_param "$dependency" + path=$(dirname "$(dirname "$manifest")") + version=$(basename "$(dirname "$manifest")") + manifest_name=$(basename "$manifest") + + # if the provided manifest does not exist in the current version, it means + # we need to copy it from a previous version. + # this could happen for example if a manifest is created in one version (e.g. 10), + # but the dependency should be added in a different, future version (e.g. 20) + if [ ! -e "$path"/"$version"/"$manifest_name" ]; then + pre_version="$version" + while [ "$pre_version" -gt 0 ] && [ ! -e "$path"/"$pre_version"/"$manifest_name" ]; do + pre_version=$(awk '/previous/ { print $2 }' "$path"/"$pre_version"/Manifest.MoM) + done + sudo cp "$path"/"$pre_version"/"$manifest_name" "$path"/"$version"/"$manifest_name" + sudo sed -i "s/version:.*/version:\\t$version/" "$manifest" + sudo sed -i "s/previous:.*/previous:\\t$pre_version/" "$manifest" + fi + sudo sed -i "s/timestamp:.*/timestamp:\\t$(date +"%s")/" "$manifest" sudo sed -i "/contentsize:.*/a includes:\\t$dependency" "$manifest" # If a manifest tar already exists for that manifest, renew the manifest tar sudo rm -f "$manifest".tar create_tar "$manifest" + update_hashes_in_mom "$path"/"$version"/Manifest.MoM }