📎 Test binfile import limit configuration

Verify that configured limits decode and reach the importer, and that
missing values use the existing defaults.

AI-assisted-by: gpt-6.1-terra
This commit is contained in:
Andrey Antukh 2026-11-26 18:02:57 +00:00
parent 640a9665a2
commit cf4e0ded38
2 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,48 @@
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) KALEIDOS SUBSIDIARY SL
(ns backend-tests.binfile-config-test
(:require
[app.binfile.common :as bfc]
[app.binfile.v3 :as v3]
[app.config :as cf]
[clojure.test :as t]))
(t/deftest import-limits-reach-the-importer
(let [values {:binfile-import-max-text-entry-size 101
:binfile-import-max-text-total-size 202
:binfile-import-max-binary-entry-size 303
:binfile-import-max-zip-entries 404}]
(binding [cf/config (merge cf/config values)]
(doseq [[key value] values]
(t/is (= value (cf/get key))))
(let [cfg (bfc/import-cfg {} {:team {:features #{}}})
resolved (#'v3/setup-limits cfg)]
(t/is (= 101 (::bfc/import-max-text-entry-size cfg) (::v3/max-text-entry-size resolved)))
(t/is (= 202 (::bfc/import-max-text-total-size cfg) (::v3/max-text-total-size resolved)))
(t/is (= 303 (::bfc/import-max-binary-entry-size cfg) (::v3/max-binary-entry-size resolved)))
(t/is (= 404 (::bfc/import-max-zip-entries cfg) (::v3/max-zip-entries resolved)))))))
(t/deftest import-limits-default-when-unconfigured
(let [keys [:binfile-import-max-text-entry-size
:binfile-import-max-text-total-size
:binfile-import-max-binary-entry-size
:binfile-import-max-zip-entries]]
(binding [cf/config (apply dissoc cf/config keys)]
(let [cfg (bfc/import-cfg {} {:team {:features #{}}})
resolved (#'v3/setup-limits cfg)
other (#'v3/setup-limits cfg)]
(t/is (nil? (::bfc/import-max-text-entry-size cfg)))
(t/is (nil? (::bfc/import-max-text-total-size cfg)))
(t/is (nil? (::bfc/import-max-binary-entry-size cfg)))
(t/is (nil? (::bfc/import-max-zip-entries cfg)))
(t/is (= bfc/default-max-text-entry-size (::v3/max-text-entry-size resolved)))
(t/is (= bfc/default-max-text-total-size (::v3/max-text-total-size resolved)))
(t/is (= bfc/default-max-binary-entry-size (::v3/max-binary-entry-size resolved)))
(t/is (= bfc/default-max-zip-entries (::v3/max-zip-entries resolved)))
(t/is (= 0 @(::v3/accumulated-total-text-size resolved)))
(t/is (not (identical? (::v3/accumulated-total-text-size resolved)
(::v3/accumulated-total-text-size other))))))))

View File

@ -76,6 +76,23 @@
:worker-default-parallelism 4)]
(t/is (= 4 (cf/get :worker-default-parallelism 1))))))
(t/deftest binfile-import-limit-keys
(let [values {:binfile-import-max-text-entry-size "101"
:binfile-import-max-text-total-size "202"
:binfile-import-max-binary-entry-size "303"
:binfile-import-max-zip-entries "404"}
decoded (cf/decode-config values)]
(t/is (= {:binfile-import-max-text-entry-size 101
:binfile-import-max-text-total-size 202
:binfile-import-max-binary-entry-size 303
:binfile-import-max-zip-entries 404}
decoded))
(t/is (cf/validate-config (merge cf/config decoded)))
(doseq [key (keys values)]
(t/testing (str "non-numeric value for " key)
(let [invalid (cf/decode-config (assoc values key "invalid"))]
(t/is (not (cf/validate-config (merge cf/config invalid)))))))))
(t/deftest prepared-statement-cache-keys
(t/testing "negative sizes are rejected; the threshold takes -1 or non-negatives"
(t/is (not (cf/validate-config (assoc cf/config :database-prepared-statement-cache-queries -1))))