-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(maint) Clean up with-additional-classpath-entries test
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
Showing
2 changed files
with
11 additions
and
20 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)))))) |