Skip to content

Commit

Permalink
Sort content of txt files in study dir to make order not important wh…
Browse files Browse the repository at this point in the history
…ile comparing
  • Loading branch information
forus committed Dec 24, 2024
1 parent 0a8a801 commit a03a98e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 9 deletions.
45 changes: 45 additions & 0 deletions test/integration/copy_and_sort.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

# Function to display usage instructions
usage() {
echo "Usage: $0 <source_directory> <destination_directory>"
exit 1
}

# Check if the correct number of arguments is provided
if [ "$#" -ne 2 ]; then
usage
fi

# Remove trailing slashes from paths if they exist
SOURCE_DIR="${1%/}"
DEST_DIR="${2%/}"

# Check if the source directory exists
if [ ! -d "$SOURCE_DIR" ]; then
echo "Error: Source directory does not exist."
exit 1
fi

# Create the destination directory if it does not exist
mkdir -p "$DEST_DIR"

# Copy files and sort text files
find "$SOURCE_DIR" -type f | while read -r FILE; do
REL_PATH="${FILE#$SOURCE_DIR/}" # Get relative path
DEST_FILE="$DEST_DIR/$REL_PATH" # Destination file path
DEST_DIR_PATH="$(dirname "$DEST_FILE")" # Destination directory path

# Create the destination directory if it does not exist
mkdir -p "$DEST_DIR_PATH"

# Check if the file is a text file and sort its contents
if file "$FILE" | grep -q "text"; then
sort "$FILE" > "$DEST_FILE"
else
cp "$FILE" "$DEST_FILE"
fi

done

echo "Copy and sort operation completed successfully."
20 changes: 20 additions & 0 deletions test/integration/in_service_import_export_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# exit when any of these fails
set -e

echo "Importing of the test study with API validation..."
metaImport.py -v -u http://cbioportal-container:8080 -o -s /cbioportal/test/test_data/study_es_0_import_export/

echo "Exporting of the test study."
curl -s http://cbioportal-container:8080/export/study/study_es_0_import_export.zip > study_es_0_import_export.zip \
&& unzip study_es_0_import_export.zip -d ./output_study_es_0_import_export

echo "Sort content of text files from both folders to make order during comparison unimportant."
./cbioportal/test/integration/copy_and_sort.sh /cbioportal/test/test_data/study_es_0_import_export/ ./input_study_es_0_import_export_sorted/
./cbioportal/test/integration/copy_and_sort.sh ./output_study_es_0_import_export/ ./output_study_es_0_import_export_sorted/

echo "Comparing the original and exported studies."
diff --recursive ./input_study_es_0_import_export_sorted/ ./output_study_es_0_import_export_sorted/

exit 0
10 changes: 1 addition & 9 deletions test/integration/test_import_export.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ run_in_service() {
return $? # return the exit code of the last command
}

echo "Importing of the test study with API validation..."
run_in_service cbioportal 'metaImport.py -v -u http://cbioportal-container:8080 -o -s /cbioportal/test/test_data/study_es_0_import_export/'

echo "Exporting of the test study."
run_in_service cbioportal 'curl -s http://cbioportal-container:8080/export/study/study_es_0_import_export.zip > study_es_0_import_export.zip && unzip study_es_0_import_export.zip -d ./output_study_es_0_import_export'

echo "Comparing the original and exported studies."
# TODO ignore order of lines in files
run_in_service cbioportal 'diff --recursive /cbioportal/test/test_data/study_es_0_import_export/ ./output_study_es_0_import_export'
run_in_service cbioportal '/cbioportal/test/integration/in_service_import_export_test.sh'

exit 0

0 comments on commit a03a98e

Please sign in to comment.