From d262a3d2972145504740dfd5d58e14d9cd6f94cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Sat, 21 May 2022 18:23:21 +0300 Subject: [PATCH] test(fixtures): add fixture test for auto deletion --- .../test-server-auto-deletion/config.toml | 10 ++++++++ fixtures/test-server-auto-deletion/test.sh | 24 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 fixtures/test-server-auto-deletion/config.toml create mode 100755 fixtures/test-server-auto-deletion/test.sh diff --git a/fixtures/test-server-auto-deletion/config.toml b/fixtures/test-server-auto-deletion/config.toml new file mode 100644 index 0000000..e40719b --- /dev/null +++ b/fixtures/test-server-auto-deletion/config.toml @@ -0,0 +1,10 @@ +[server] +address="127.0.0.1:8000" +max_content_length="10MB" +upload_path="./upload" + +[paste] +random_url = { enabled = true, type = "petname", words = 2, separator = "-" } +default_extension = "txt" +duplicate_files = true +delete_expired_files = { enabled = true, interval = "2s" } diff --git a/fixtures/test-server-auto-deletion/test.sh b/fixtures/test-server-auto-deletion/test.sh new file mode 100755 index 0000000..3065ac6 --- /dev/null +++ b/fixtures/test-server-auto-deletion/test.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +content="test content" + +setup() { + echo "$content" > file +} + +run_test() { + first_file_url=$(curl -s -F "file=@file" -H "expire:1s" localhost:8000) + second_file_url=$(curl -s -F "file=@file" -H "expire:4s" localhost:8000) + test "$content" = "$(curl -s $first_file_url)" + test "$content" = "$(curl -s $second_file_url)" + sleep 3s + test "file is not found or expired :(" = "$(curl -s $first_file_url)" + test "$content" = "$(curl -s $second_file_url)" + sleep 1s + test "file is not found or expired :(" = "$(curl -s $second_file_url)" +} + +teardown() { + rm file + rm -r upload +}