-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for the cassandra/schema/create.sh script (#6594)
## Which problem is this PR solving? - Subpart of the #6582 ## Description of the changes - created unit tests for the create.sh file , to test for various cases such as presence of Mode parameter , output for specific parameters ## How was this change tested? - ## Checklist - [X] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [X] I have signed all commits - [X] I have added unit tests for the new functionality - [ ] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `npm run lint` and `npm run test` --------- Signed-off-by: asim <aktech701@gmail.com>
- Loading branch information
1 parent
5c9f16d
commit c2ea27a
Showing
3 changed files
with
159 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/bin/bash | ||
# Copyright (c) 2025 The Jaeger Authors. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# This script uses https://github.com/kward/shunit2 to run unit tests. | ||
# The path to this repo must be provided via SHUNIT2 env var. | ||
|
||
SHUNIT2="${SHUNIT2:?'expecting SHUNIT2 env var pointing to a dir with https://github.com/kward/shunit2 clone'}" | ||
|
||
|
||
createScript="$(dirname $0)/create.sh" | ||
|
||
|
||
unset MODE | ||
unset DATACENTER | ||
unset KEYSPACE | ||
unset REPLICATION | ||
unset REPLICATION_FACTOR | ||
unset TRACE_TTL | ||
unset DEPENDENCIES_TTL | ||
unset COMPACTION_WINDOW | ||
unset VERSION | ||
|
||
testRequireMode() { | ||
err=$(bash "$createScript" 2>&1) | ||
assertContains "$err" "missing MODE parameter" | ||
} | ||
|
||
testInvalidMode() { | ||
err=$(MODE=invalid bash "$createScript" 2>&1) | ||
assertContains "$err" "invalid MODE=invalid, expecting 'prod' or 'test'" | ||
} | ||
|
||
testProdModeRequiresDatacenter() { | ||
err=$(MODE=prod bash "$createScript" 2>&1) | ||
assertContains "$err" "missing DATACENTER parameter for prod mode" | ||
} | ||
|
||
testProdModeWithDatacenter() { | ||
out=$(MODE=prod DATACENTER=dc1 bash "$createScript" 2>&1) | ||
assertContains "$out" "mode = prod" | ||
assertContains "$out" "datacenter = dc1" | ||
assertContains "$out" "replication = {'class': 'NetworkTopologyStrategy', 'dc1': '2' }" | ||
} | ||
|
||
testTestMode() { | ||
out=$(MODE=test bash "$createScript" 2>&1) | ||
assertContains "$out" "mode = test" | ||
assertContains "$out" "datacenter = test" | ||
assertContains "$out" "replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}" | ||
} | ||
|
||
testCustomTTL() { | ||
out=$(MODE=test TRACE_TTL=86400 DEPENDENCIES_TTL=172800 bash "$createScript" 2>&1) | ||
assertContains "$out" "trace_ttl = 86400" | ||
assertContains "$out" "dependencies_ttl = 172800" | ||
} | ||
|
||
testInvalidKeyspace() { | ||
err=$(MODE=test KEYSPACE=invalid-keyspace bash "$createScript" 2>&1) | ||
assertContains "$err" "invalid characters in KEYSPACE" | ||
} | ||
|
||
testValidKeyspace() { | ||
out=$(MODE=test KEYSPACE=valid_keyspace_123 bash "$createScript" 2>&1) | ||
assertContains "$out" "keyspace = valid_keyspace_123" | ||
} | ||
|
||
testCustomCompactionWindow() { | ||
out=$(MODE=test COMPACTION_WINDOW=24h bash "$createScript" 2>&1) | ||
assertContains "$out" "compaction_window_size = 24" | ||
assertContains "$out" "compaction_window_unit = HOURS" | ||
} | ||
|
||
testInvalidCompactionWindow() { | ||
err=$(MODE=test COMPACTION_WINDOW=24x bash "$createScript" 2>&1) | ||
assertContains "$err" "Invalid compaction window size format" | ||
} | ||
|
||
testCustomVersion() { | ||
out=$(MODE=test VERSION=3 bash "$createScript" 2>&1) | ||
assertContains "$out" "v003.cql.tmpl" | ||
} | ||
|
||
|
||
source "${SHUNIT2}/shunit2" |
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,71 @@ | ||
#!/bin/bash | ||
|
||
# Copyright (c) 2025 The Jaeger Authors. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
|
||
UTILS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
REPO_ROOT="$UTILS_DIR/../.." | ||
|
||
# Define list of test files explicitly here , to be dynamic to the location of the test file | ||
TEST_FILES=( | ||
"$UTILS_DIR/compute-tags.test.sh" | ||
"$REPO_ROOT/plugin/storage/cassandra/schema/create.test.sh" | ||
) | ||
|
||
run_test_file() { | ||
local test_file="$1" | ||
if [ ! -f "$test_file" ]; then | ||
echo "Error: Test file not found: $test_file" | ||
return 1 | ||
fi | ||
|
||
echo "Running tests from: $test_file" | ||
|
||
export SHUNIT2="${SHUNIT2:?'SHUNIT2 environment variable must be set'}" | ||
|
||
bash "$test_file" | ||
local result=$? | ||
echo "Test file $test_file completed with status: $result" | ||
return $result | ||
} | ||
|
||
main() { | ||
|
||
if [ ! -f "${SHUNIT2}/shunit2" ]; then | ||
echo "Error: shunit2 not found at ${SHUNIT2}/shunit2" | ||
exit 1 | ||
fi | ||
local failed=0 | ||
local total=0 | ||
local passed=0 | ||
local failed_tests=() | ||
|
||
# Run all test files | ||
for test_file in "${TEST_FILES[@]}"; do | ||
((total++)) | ||
if ! run_test_file "$test_file"; then | ||
failed=1 | ||
failed_tests+=("$test_file") | ||
else | ||
((passed++)) | ||
fi | ||
done | ||
|
||
echo "-------------------" | ||
echo "Test Summary:" | ||
echo "Total: $total" | ||
echo "Passed: $passed" | ||
echo "Failed: $((total - passed))" | ||
|
||
if [ ${#failed_tests[@]} -gt 0 ]; then | ||
echo "Failed tests:" | ||
for test in "${failed_tests[@]}"; do | ||
echo " - $(basename "$test")" | ||
done | ||
fi | ||
|
||
exit $failed | ||
} | ||
|
||
main |