Skip to content

Commit

Permalink
(maint) Clean up with-additional-classpath-entries test
Browse files Browse the repository at this point in the history
The implementation of this test was not ideal, and made worse by Java 9 changes
to classloaders. Instead of querying URLs, just add a resource to a directory
that's not normally in the class path and test that we can resolve it when it's
added and that we can't after it gets cleaned up.
  • Loading branch information
pcarlisle committed Jan 18, 2018
1 parent 5d5f484 commit 00495b7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
Empty file.
31 changes: 11 additions & 20 deletions test/puppetlabs/kitchensink/classpath_test.clj
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
(ns puppetlabs.kitchensink.classpath-test
(:require [clojure.test :refer :all]
[dynapath.dynamic-classpath :refer [classpath-urls]]
[puppetlabs.kitchensink.classpath :refer [add-classpath
with-additional-classpath-entries]])
(:import (java.net URL))
(:refer-clojure :exclude (add-classpath)))
[puppetlabs.kitchensink.classpath :refer [with-additional-classpath-entries]])
(:import (java.net URL)))

(deftest with-additional-classpath-entries-test
(let [paths ["/foo" "/bar"]
get-urls #(into #{}
(classpath-urls (.getContextClassLoader (Thread/currentThread))))]
;; Called for side effect of ensuring there's a modifiable classloader
;; without needing to make that function public
(add-classpath "file:/nil")

(let [paths ["classpath-test"]
get-resource #(-> (Thread/currentThread)
.getContextClassLoader
(.getResource "does-not-exist-anywhere-else"))]
(with-additional-classpath-entries
paths
(testing "classloader now includes the new paths"
(let [urls (get-urls)]
(is (contains? urls (URL. "file:/foo")))
(is (contains? urls (URL. "file:/bar"))))))
(testing "classloader has been restored to its previous state"
(let [urls (get-urls)]
(is (not (contains? urls (URL. "file:/foo"))))
(is (not (contains? urls (URL. "file:/bar"))))))))
(testing "classloader now includes the new path"
(is (get-resource))))

(testing "classloader no longer includes the new path"
(is (not (get-resource))))))

0 comments on commit 00495b7

Please sign in to comment.