   [catalogs resource-type resource-title]
   (count (filter #(catalog-contains? % resource-type resource-title) catalogs)))
 
-(schema/defn ^:always-validate with-puppet-conf-files
+(defmacro with-puppet-conf-files
+  "A macro that can be used to wrap a single test with the setup and teardown
+  of with-puppet-conf.
+
+  Accepts a map with the following characteristics:
+
+  * keys are simple filenames (no paths) that will be created in puppet's $confdir
+  * values are paths to a test-specific file that should be copied to puppet's confdir,
+    a la `$confdir/<key>`.
+
+  For each entry in the map, copies the files into $confdir, runs the test function,
+  and then deletes all of the files from $confdir.
+
+  Optionally accepts a second argument `dest-dir`, which specifies the location
+  of Puppet's $confdir.  If this argument is not provided, defaults to
+  `jruby-testutils/conf-dir`."
+  [puppet-conf-files dest-dir & body]
+  `(let [target-paths# (get-with-puppet-conf-target-paths ~puppet-conf-files ~dest-dir)]
+     (copy-with-puppet-conf-files-into-place! ~puppet-conf-files target-paths#)
+     (try
+       ~@body
+       (finally
+         (cleanup-with-puppet-conf-files! target-paths#)))))
+
+(schema/defn ^:always-validate with-puppet-conf-fixture
   "Test fixture; Accepts a map with the following characteristics:
 
   * keys are simple filenames (no paths) that will be created in puppet's $confdir


  Optionally accepts a second argument `dest-dir`, which specifies the location
  of Puppet's $confdir.  If this argument is not provided, defaults to
  `testutils/conf-dir`."
  ([puppet-conf-files]
   (with-puppet-conf-files puppet-conf-files conf-dir))
  ([puppet-conf-files :- {schema/Str (schema/pred (some-fn string? #(instance? File %)))}
    dest-dir :- schema/Str]

   (let [target-paths (reduce
                       (fn [acc filename]
                         (assoc acc filename (fs/file dest-dir filename)))
                       {}
                       (keys puppet-conf-files))]
     (fn [f]
       (doseq [filename (keys puppet-conf-files)]
         (fs/copy+ (get puppet-conf-files filename)
                   (get target-paths filename)))
       (try
         (f)
         (finally
           (doseq [target-path (vals target-paths)]
             (fs/delete target-path))))))))

(defn with-puppet-conf
  "This function returns a test fixture that will copy a specified puppet.conf

  ([puppet-conf-file]
   (with-puppet-conf puppet-conf-file conf-dir))
  ([puppet-conf-file dest-dir]
   (with-puppet-conf-fixture {"puppet.conf" puppet-conf-file} dest-dir)))
