simuons / rules_clojure

Clojure rules for Bazel
Apache License 2.0
34 stars 8 forks source link

Testing with static resources #58

Open symbiont-sean-lyons opened 3 years ago

symbiont-sean-lyons commented 3 years ago

It does not look like clojure_test supports attributes resources or data the way that java rules do. Any advice on how to support a use-case where my unit tests depend on static resources?

My project is structured like so

test/
|- my_test.clj
|- testdata/
|--- data.edn

and I just want to be able to access my .edn file from my_test.clj, for example (slurp "testdata/data.edn").

I tried to exposing the testdata as a file group, but clojure_test cannot depend on something that does not provide JavaInfo.

Additionally, I tried to package my testdata in a java library like so

--- test/BUILD
 clojure_test(
     name = "test",
     deps = [
         "//test/testdata/data",
     ],
     srcs = [
         "my_test.clj",
     ],
 )

--- testdata/BUILD
 java_library(
     name = "data",
     resources = glob(["*.edn"]),
     visibility = ["//visibility:public"],
 )

I would not be surprised if the jar approach makes no sense, I just gave it a shot :)

Appreciate any advice you can offer