Commit b8775744 authored by Andrew Roetker's avatar Andrew Roetker

(PDB-2126) Add clarifying comment about weird code_id code

This commit adds a comment about the defaulting of the `code_id` code in
the terminus to explain that `hash[code_id] = hash[code_id]` is simply
ensuring that the `hash` has the `code_id` key.
parent 7ef75d23
......@@ -122,6 +122,9 @@ class Puppet::Resource::Catalog::Puppetdb < Puppet::Indirector::REST
# @return [Hash] returns original hash with a gaurunteed code_id key
# @api private
def add_code_id_if_missing(hash)
# This weird code ensure that `hash` will always have a `code_id` key and if
# it already had a `code_id` key we use that as the value. If `hash` didn't
# have a `code_id` key the lookup will return nil and hash['code_id'] == nil
hash['code_id'] = hash['code_id']
(ns puppetlabs.puppetdb.acceptance.cli
(:require [clojure.test :refer :all]
[puppetlabs.puppetdb.client :as pdb-client]
[puppetlabs.puppetdb.cli.export :as cli-export]
[puppetlabs.puppetdb.cli.import :as cli-import]
[puppetlabs.puppetdb.anonymizer :as anon]
[puppetlabs.puppetdb.testutils :as tu]
[puppetlabs.puppetdb.testutils.facts :as tuf]
[puppetlabs.puppetdb.testutils.reports :as tur]
[puppetlabs.puppetdb.testutils.catalogs :as tuc]
[ :as svc-utils]
:refer [get-nodes get-catalogs get-factsets get-reports munge-tar-map
example-catalog example-report example-facts example-certname]]
[puppetlabs.puppetdb.testutils.tar :refer [tar->map]]))
(deftest test-anonymized-export-roundtrip
(doseq [profile (keys anon/anon-profiles)]
(let [export-out-file (.getPath (tu/temp-file "export-test" ".tar.gz"))
anon-out-file (.getPath (tu/temp-file "anon-test" ".tar.gz"))]
(fn []
(is (empty? (get-nodes)))
(svc-utils/sync-command-post (svc-utils/pdb-cmd-url) example-certname
"replace catalog" 8 example-catalog)
(svc-utils/sync-command-post (svc-utils/pdb-cmd-url) example-certname
"store report" 7 example-report)
(svc-utils/sync-command-post (svc-utils/pdb-cmd-url) example-certname
"replace facts" 4 example-facts)
(is (= (tuc/munge-catalog example-catalog)
(tuc/munge-catalog (get-catalogs example-certname))))
(is (= [example-report] (get-reports example-certname)))
(is (= (tuf/munge-facts example-facts)
(tuf/munge-facts (get-factsets example-certname))))
(#'cli-export/-main "--outfile" export-out-file
"--host" (:host svc-utils/*base-url*)
"--port" (str (:port svc-utils/*base-url*)))
(#'cli-export/-main "--outfile" anon-out-file
"--anonymization" profile
"--host" (:host svc-utils/*base-url*)
"--port" (str (:port svc-utils/*base-url*)))
(let [export-out-map (munge-tar-map (tar->map export-out-file))
anon-out-map (munge-tar-map (tar->map anon-out-file))]
(if (= profile "none")
(is (= export-out-map anon-out-map))
(is (not= export-out-map anon-out-map))))))
(let [anon-out-map (tar->map anon-out-file)
anon-certname (some-> anon-out-map (get "reports") first val (get "certname"))]
(fn []
(is (empty? (get-nodes)))
(#'cli-import/-main "--infile" anon-out-file
"--host" (:host svc-utils/*base-url*)
"--port" (str (:port svc-utils/*base-url*)))
@(tu/block-until-results 100 (first (get-catalogs anon-certname)))
@(tu/block-until-results 100 (first (get-reports anon-certname)))
@(tu/block-until-results 100 (first (get-factsets anon-certname)))
(is (not (empty? (get-catalogs anon-certname))))
(is (not (empty? (get-reports anon-certname))))
(is (not (empty? (get-factsets anon-certname))))))))))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment