Refactoring & tests
This commit is contained in:
Executable
+71
@@ -0,0 +1,71 @@
|
||||
#!/bin/bash
|
||||
# Mock für wget - simuliert GitHub API und Downloads
|
||||
|
||||
MOCK_DIR="$(dirname "$0")/../fixtures"
|
||||
MOCK_STATE_FILE="${MOCK_DIR}/wget_state"
|
||||
|
||||
# State laden (welche Version soll zurückgegeben werden?)
|
||||
if [[ -f "${MOCK_STATE_FILE}" ]]; then
|
||||
# shellcheck source=/dev/null
|
||||
source "${MOCK_STATE_FILE}"
|
||||
fi
|
||||
|
||||
# Defaults
|
||||
WGET_LATEST_VERSION="${WGET_LATEST_VERSION:-0.10.15}"
|
||||
WGET_DOWNLOAD_SUCCESS="${WGET_DOWNLOAD_SUCCESS:-true}"
|
||||
WGET_DOWNLOAD_FILE="${WGET_DOWNLOAD_FILE:-${MOCK_DIR}/Logseq-linux-x64-0.10.15.AppImage}"
|
||||
|
||||
case "$*" in
|
||||
*releases/latest*)
|
||||
# Simuliere GitHub Release-Seite
|
||||
echo "<html><body><a href=\"/logseq/logseq/releases/tag/${WGET_LATEST_VERSION}\">Latest</a></body></html>"
|
||||
;;
|
||||
|
||||
*Logseq-linux-x64-*.AppImage*)
|
||||
# Download simulieren
|
||||
if [[ "${WGET_DOWNLOAD_SUCCESS}" == "true" ]]; then
|
||||
# Output-Datei ermitteln (-qO oder -O)
|
||||
output_file=""
|
||||
for i in "$@"; do
|
||||
case $i in
|
||||
-qO|-O)
|
||||
output_file="$2"
|
||||
shift 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -n "${output_file}" ]]; then
|
||||
cp "${WGET_DOWNLOAD_FILE}" "${output_file}"
|
||||
else
|
||||
cat "${WGET_DOWNLOAD_FILE}"
|
||||
fi
|
||||
exit 0
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
*raw.githubusercontent.com*logseq.png*)
|
||||
# Icon-Download
|
||||
output_file=""
|
||||
for i in "$@"; do
|
||||
case $i in
|
||||
-qO|-O)
|
||||
output_file="$2"
|
||||
shift 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -n "${output_file}" ]]; then
|
||||
# Dummy PNG erstellen (1x1 pixel)
|
||||
printf '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x02\x00\x00\x00\x90wS\xde\x00\x00\x00\x0cIDAT\x08\xd7c\xf8\xff\xff\x3f\x00\x05\xfe\x02\xfe\xa7\x0f\x9d\x1e\x00\x00\x00\x00IEND\xaeB`\x82' > "${output_file}"
|
||||
fi
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Mock wget: unbekannter Aufruf: $*" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user