-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
typo fix for certificate template script in Automate HA (#8616)
* typo fix for certificate error Signed-off-by: punitmundra <pmundra@progress.com> * add testcase for semver Signed-off-by: punitmundra <pmundra@progress.com> * fix path Signed-off-by: punitmundra <pmundra@progress.com> * fix path Signed-off-by: punitmundra <pmundra@progress.com> --------- Signed-off-by: punitmundra <pmundra@progress.com>
- Loading branch information
1 parent
c7b9970
commit 17c8fc1
Showing
4 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
terraform/a2ha-terraform/modules/automate/templates/script/semver.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
semver_version_check() { | ||
installed_version=$1 | ||
airgap_bundle_version=$2 | ||
|
||
IFS='.' read -r major1 minor1 patch1 <<< "$installed_version" | ||
IFS='.' read -r major2 minor2 patch2 <<< "$airgap_bundle_version" | ||
|
||
# Compare major versions | ||
if (( major1 > major2 )); then | ||
echo "$installed_version is greater than $airgap_bundle_version" | ||
isSkipRequired=true | ||
elif (( major1 < major2 )); then | ||
echo "$airgap_bundle_version is greater than $installed_version, proceeding for upgrade" | ||
else | ||
# Compare minor versions | ||
if (( minor1 > minor2 )); then | ||
echo "$installed_version is greater than $airgap_bundle_version" | ||
isSkipRequired=true | ||
elif (( minor1 < minor2 )); then | ||
echo "$airgap_bundle_version is greater than $installed_version, proceeding for upgrade" | ||
else | ||
# Compare patch versions | ||
if (( patch1 > patch2 )); then | ||
echo "$installed_version is greater than $airgap_bundle_version" | ||
isSkipRequired=true | ||
elif (( patch1 < patch2 )); then | ||
echo "$airgap_bundle_version is greater than $installed_version, proceeding for upgrade" | ||
else | ||
echo "Both versions are equal" | ||
isSkipRequired=true | ||
fi | ||
fi | ||
fi | ||
} |
62 changes: 62 additions & 0 deletions
62
terraform/a2ha-terraform/modules/automate/templates/script/test_semver.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
source ./semver.sh | ||
# Function to assert equality of output | ||
assert_equals() { | ||
local expected="$1" | ||
local actual="$2" | ||
if [ "$expected" == "$actual" ]; then | ||
echo "Test Passed" | ||
else | ||
echo "Test Failed: Expected '$expected', but got '$actual'" | ||
exit 1 | ||
fi | ||
} | ||
|
||
# Test case 1: Installed version is greater than airgap bundle version | ||
test_case_1() { | ||
echo "Running Test Case 1: Installed version > Airgap bundle version" | ||
result=$(semver_version_check "4.13.0" "4.12.144") | ||
assert_equals "4.13.0 is greater than 4.12.144" "$result" | ||
} | ||
|
||
# Test case 2: Airgap bundle version is greater than installed version | ||
test_case_2() { | ||
echo "Running Test Case 2: Airgap bundle version > Installed version" | ||
result=$(semver_version_check "4.12.144" "4.13.0") | ||
assert_equals "4.13.0 is greater than 4.12.144, proceeding for upgrade" "$result" | ||
} | ||
|
||
# Test case 3: Both versions are equal | ||
test_case_3() { | ||
echo "Running Test Case 3: Both versions are equal" | ||
result=$(semver_version_check "4.12.144" "4.12.144") | ||
assert_equals "Both versions are equal" "$result" | ||
} | ||
|
||
# Test case 4: Different patch version | ||
test_case_4() { | ||
echo "Running Test Case 4: Installed version has greater patch version" | ||
result=$(semver_version_check "4.12.145" "4.12.144") | ||
assert_equals "4.12.145 is greater than 4.12.144" "$result" | ||
} | ||
|
||
# Test case 5: Different minor version | ||
test_case_5() { | ||
echo "Running Test Case 5: Airgap bundle has greater minor version" | ||
result=$(semver_version_check "4.11.144" "4.12.0") | ||
assert_equals "4.12.0 is greater than 4.11.144, proceeding for upgrade" "$result" | ||
} | ||
|
||
# Test case 6: Different major minor and patch version | ||
test_case_6() { | ||
echo "Running Test Case 6: Airgap bundle has greater major version" | ||
result=$(semver_version_check "4.11.144" "5.12.99") | ||
assert_equals "5.12.99 is greater than 4.11.144, proceeding for upgrade" "$result" | ||
} | ||
# Run all test cases | ||
test_case_1 | ||
test_case_2 | ||
test_case_3 | ||
test_case_4 | ||
test_case_5 | ||
test_case_6 | ||
echo "All tests passed!" |