From ef5f99bb74390af937f3c9ea42465b92110034f9 Mon Sep 17 00:00:00 2001 From: Ryan Senior Date: Thu, 1 Nov 2018 10:31:10 -0500 Subject: [PATCH] Fix test checksum test failure on MySQL [ci drivers] The newly added checksum tests fail when running on MySQL in Circle. The MySQL tests include a secret key for encryption which are used when computing the checksum. Because of that encryption, the checksum string is different every time (it must be decrypted before compared). The test isn't covering the encryption code but is only concerned with ensure the datastructure hashes consitently. This commit uses a `with-redefs` to set that secret key to `nil` so that encryption won't be used on those two tests. --- .../middleware/results_metadata_test.clj | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/test/metabase/query_processor/middleware/results_metadata_test.clj b/test/metabase/query_processor/middleware/results_metadata_test.clj index 36700b0d7e803..e9b55f6d84348 100644 --- a/test/metabase/query_processor/middleware/results_metadata_test.clj +++ b/test/metabase/query_processor/middleware/results_metadata_test.clj @@ -16,6 +16,7 @@ [util :as tu]] [metabase.test.data.users :as users] [metabase.test.mock.util :as mutil] + [metabase.util.encryption :as encrypt] [toucan.db :as db] [toucan.util.test :as tt])) @@ -119,15 +120,23 @@ [m] (apply hash-map (apply concat m))) +(defn- metadata-checksum + "Invoke `metadata-checksum` without a `default-secret-key` specified. If the key is specified, it will encrypt the + checksum. The encryption includes random data that will cause the checksum string to be different each time, so the + checksum strings can't be directly compared." + [metadata] + (with-redefs [encrypt/default-secret-key nil] + (#'results-metadata/metadata-checksum metadata))) + ;; tests that the checksum is consistent when an array-map is switched to a hash-map (expect - (#'results-metadata/metadata-checksum example-metadata) - (#'results-metadata/metadata-checksum (mapv array-map->hash-map example-metadata))) + (metadata-checksum example-metadata) + (metadata-checksum (mapv array-map->hash-map example-metadata))) ;; tests that the checksum is consistent with an integer and with a double (expect - (#'results-metadata/metadata-checksum example-metadata) - (#'results-metadata/metadata-checksum (update-in example-metadata [1 :fingerprint :type :type/Number :min] int))) + (metadata-checksum example-metadata) + (metadata-checksum (update-in example-metadata [1 :fingerprint :type :type/Number :min] int))) ;; make sure that queries come back with metadata (expect