Fork me on GitHub
#babashka
<
2023-07-11
>
Stephan Renatus09:07:50

probably a beginner mistake — trying to run http-server in a docker-container based on babashka/babashka, I’m greeted with Couldn't find 'java'. Please set JAVA_HOME. — what am I missing?

borkdude09:07:48

If you are using dependencies in bb.edn then you need to have java installed to download them

Stephan Renatus09:07:25

OK. so I guess that’s what happens at runtime in the http-server script https://github.com/babashka/http-server#babashka?

Stephan Renatus09:07:48

any chance to use the docker image for this then? I guess not

borkdude09:07:32

if you want to download dependencies without java, it's probably better to make an uberjar and then add this to your docker image

borkdude09:07:55

or use a staged image

Stephan Renatus09:07:31

I think this is becoming too much overhead, if I just found a way to start a binary for having tests run against that service, I wouldn’t need docker in the first place

borkdude09:07:37

for simple dependencies you can also just git clone the dependency and add manually to the classpath:

bb -cp ~/Downloads/http-server/src ...

Stephan Renatus09:07:44

sorry — X vs Y problem here on my end

Stephan Renatus09:07:26

let me start over: I’ve got two simple http/get API tests that I’d like to run against a service. can you give me a hint on how to start the service before tests and tear it down after? 😅

borkdude09:07:07

does the service or the test run in bb, or both?

Stephan Renatus09:07:50

only the tests are running in bb, the service is a little golang-built binary

borkdude09:07:28

then I'm even more confused :)

borkdude09:07:43

what does this have to do with bb then?

borkdude09:07:59

I mean, why did you need http-server in bb?

Stephan Renatus09:07:16

I’d like to do API tests like

(deftest authorized-cars
  (testing "bob is authorized to list all cars"
    (let [status (:status (request {"Authorization" "bob"}))]
      (is (= 200 status)))))
ohh I see why this is confusing sorry

Stephan Renatus09:07:35

the piece I forgot to mention: the app needs to retrieve something via HTTP from a static file server

Stephan Renatus09:07:52

I’m sorry it’s really hot today 💦

borkdude09:07:21

> can you give me a hint on how to start the service before tests and tear it down after? clojure.test has fixtures for this

borkdude09:07:38

it's hot here too, hehe

Stephan Renatus09:07:41

so, my initial try was to start the service, and some file server, via docker-compose, and then have a bb run test:api job. now, I’m trying to do it all from bb, starting the service and the auxilliary file server

Stephan Renatus09:07:54

clojure.test. thanks, I’ll go read up on that end.

Stephan Renatus09:07:32

oh this is great thank you

joakimen23:07:07

(babashka.fs/directory? "") ;; => true
Was expecting false here, is this intended?

Bob B23:07:49

that fn calls as-path on the argument, which calls io/file on it, so it gets treated as a relative path, so it's essentially just the current directory

Bob B23:07:23

for example:

user=> (-> (fs/path "") .toAbsolutePath)
#object[sun.nio.fs.UnixPath 0x3bc3dc17 "/home/bob"]

joakimen00:07:36

Looks like it yeah, no idea about the rationale for why an empty UnixPath resolves to current dir, but I guess that's just a java thing and nothing wrong on this end then!

joakimen00:07:10

Thanks for testing!

Bob B00:07:34

I imagine it's sort of a circumstantial outcome of the rules of the File class - if the path doesn't start with a prefix that signifies it's an absolute path, it's relative, and since it's relative, it appends the string path to user.dir, and so appending an empty string returns the path at user.dir

joakimen00:07:42

I had no idea that "relative" in java File meant "relative to the home dir of the current user" instead of the usual "relative to the current directory of the calling process" think_beret but the explanation makes sense then

Bob B01:07:49

well, that was only because I happened to be running bb in my home dir.... the system property user.dir is typically the 'current dir'