From 5dc7763325778ad9e925dbf32bc3eaf0c05fc6a2 Mon Sep 17 00:00:00 2001 From: Bob Date: Sun, 26 Feb 2023 04:13:27 -0500 Subject: [PATCH] - remove zero size tolerance for overwriting uber-files (#1504) - in tests, delete temp output files that would prevent overwrite - in tests, change 'non-empty' files to be empty files (since non-empty is no longer necessary) - in hato test, replace nghttp2 with httpbin, since httpbin uses http/2 by default now, and to benefit from httpbin 'flaky' test --- src/babashka/main.clj | 3 +-- test-resources/lib_tests/hato/client_test.clj | 2 +- test/babashka/main_test.clj | 7 +++---- test/babashka/uberscript_test.clj | 14 ++++++++------ 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/babashka/main.clj b/src/babashka/main.clj index e1cee8d9..31b04037 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -785,8 +785,7 @@ Use bb run --help to show this help output. and files that are empty/don't exist." [path] (or (= "jar" (fs/extension path)) - (not (fs/exists? path)) - (zero? (fs/size path)))) + (not (fs/exists? path)))) (def seen-urls (atom nil)) diff --git a/test-resources/lib_tests/hato/client_test.clj b/test-resources/lib_tests/hato/client_test.clj index d17d7b55..7c663710 100644 --- a/test-resources/lib_tests/hato/client_test.clj +++ b/test-resources/lib_tests/hato/client_test.clj @@ -331,7 +331,7 @@ (deftest ^:integration test-http2 (testing "can make an http2 request" - (let [r (get "https://nghttp2.org/httpbin/get" {:as :json})] + (let [r (get "https://httpbin.org/get" {:as :json})] (is (= :http-2 (:version r)))))) (deftest custom-middleware diff --git a/test/babashka/main_test.clj b/test/babashka/main_test.clj index 1edc9b01..51a98905 100644 --- a/test/babashka/main_test.clj +++ b/test/babashka/main_test.clj @@ -484,14 +484,14 @@ (deftest uberscript-test (let [tmp-file (java.io.File/createTempFile "uberscript" ".clj")] (.deleteOnExit tmp-file) + (.delete tmp-file) ; prevent overwrite failure (is (empty? (bb nil "--uberscript" (test-utils/escape-file-paths (.getPath tmp-file)) "-e" "(System/exit 1)"))) (is (= "(System/exit 1)" (slurp tmp-file))))) (deftest uberscript-overwrite-test - (testing "trying to make uberscript overwrite a non-empty, non-jar file fails" + (testing "trying to make uberscript overwrite a non-jar file fails" (let [tmp-file (java.io.File/createTempFile "uberscript_overwrite" ".clj")] (.deleteOnExit tmp-file) - (spit (.getPath tmp-file) "this isn't empty") (is (thrown-with-msg? Exception #"Overwrite prohibited." (test-utils/bb nil "--uberscript" (test-utils/escape-file-paths (.getPath tmp-file)) "-e" "(println 123)")))))) @@ -516,11 +516,10 @@ (test-utils/bb nil "--uberjar" (test-utils/escape-file-paths path) "-m" "my.main-main") ; execute uberjar to confirm that the file is overwritten (is (= "(\"42\")\n" (test-utils/bb nil "--prn" "--jar" (test-utils/escape-file-paths path) "42"))))) - (testing "trying to make uberjar overwrite a non-empty, non-jar file is not allowed" + (testing "trying to make uberjar overwrite a non-jar file is not allowed" (let [tmp-file (java.io.File/createTempFile "oops_all_source" ".clj") path (.getPath tmp-file)] (.deleteOnExit tmp-file) - (spit path "accidentally a source file") (is (thrown-with-msg? Exception #"Overwrite prohibited." (test-utils/bb nil "--uberjar" (test-utils/escape-file-paths path) "-m" "my.main-main"))))))) diff --git a/test/babashka/uberscript_test.clj b/test/babashka/uberscript_test.clj index e76511cd..66376038 100644 --- a/test/babashka/uberscript_test.clj +++ b/test/babashka/uberscript_test.clj @@ -4,17 +4,20 @@ [clojure.string :as str] [clojure.test :as t :refer [deftest is]])) +(defn deleted-temp-file [] + (doto (java.io.File/createTempFile "uberscript" ".clj") + .deleteOnExit + .delete)) ; delete file to prevent overwrite failure + (deftest basic-test - (let [tmp-file (java.io.File/createTempFile "uberscript" ".clj")] - (.deleteOnExit tmp-file) + (let [tmp-file (deleted-temp-file)] (is (empty? (tu/bb nil "--prn" "--classpath" "test-resources/babashka/src_for_classpath_test" "uberscript" (.getPath tmp-file) "-m" "my.main"))) (is (= "(\"1\" \"2\" \"3\" \"4\")\n" (tu/bb nil "--prn" "--file" (.getPath tmp-file) "1" "2" "3" "4"))))) (when-not (= "aarch64" (System/getenv "BABASHKA_ARCH")) (deftest advanced-test - (let [tmp-file (java.io.File/createTempFile "uberscript" ".clj")] - (.deleteOnExit tmp-file) + (let [tmp-file (deleted-temp-file)] ;; we test: ;; order of namespaces ;; reader error for ::a/foo is swallowed @@ -25,8 +28,7 @@ (tu/bb nil "--prn" "--file" (.getPath tmp-file) "1" "2" "3" "4")))))) (deftest pods-test - (let [tmp-file (java.io.File/createTempFile "uberscript" ".clj")] - (.deleteOnExit tmp-file) + (let [tmp-file (deleted-temp-file)] (tu/with-config (pr-str '{:paths ["test-resources/babashka/uberscript/src"] :pods {org.babashka/go-sqlite3 {:version "0.1.0"}}}) (is (empty? (tu/bb nil "--prn" "uberscript" (.getPath tmp-file) "-m" "my.main-pod")))