Skip to content

Commit

Permalink
Fix test checksum test failure on MySQL [ci drivers]
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
iethree committed Nov 1, 2018
1 parent a657ce3 commit ef5f99b
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions test/metabase/query_processor/middleware/results_metadata_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]))

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ef5f99b

Please sign in to comment.