Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot run tests in lesson 27 recipes tests: "app" is null #13

Open
kentbull opened this issue Jul 5, 2023 · 6 comments
Open

Cannot run tests in lesson 27 recipes tests: "app" is null #13

kentbull opened this issue Jul 5, 2023 · 6 comments

Comments

@kentbull
Copy link

kentbull commented Jul 5, 2023

I am getting 1 error running tests near the middle of lesson 27, a NullPointerException saying the "app" is null.

It's referring to the app defined in the let binding of test-endpoint

(defn test-endpoint
  ([method uri]
   (test-endpoint method uri nil))
  ([method uri opts]
   (let [app (-> state/system :cheffy/app)
         request (app (-> (mock/request method uri)
                        (cond-> (:body opts) (mock/json-body (:body opts)))))]
     (update request :body (partial m/decode "application/json")))))

Error:

❯ lein test
2023-07-05 16:02:34.957:INFO::main: Logging initialized @977ms to org.eclipse.jetty.util.log.StdErrLog
Warning: environ value /path.../.jenv/versions/17.0 for key :java-home has been overwritten with /Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home

lein test cheffy.recipes-test

lein test :only cheffy.recipes-test/recipes-tests

ERROR in (recipes-tests) (test_system.clj:12)
Uncaught exception, not in assertion.
expected: nil
  actual: java.lang.NullPointerException: Cannot invoke "clojure.lang.IFn.invoke(Object)" because "app" is null
 at cheffy.test_system$test_endpoint.invokeStatic (test_system.clj:12)
    cheffy.test_system$test_endpoint.invoke (test_system.clj:7)
    cheffy.test_system$test_endpoint.invokeStatic (test_system.clj:9)
    cheffy.test_system$test_endpoint.invoke (test_system.clj:7)

It seems like somehow integrant is not pulling in the "app" state correctly.

@kentbull
Copy link
Author

kentbull commented Jul 5, 2023

The same problem occurs when I run lein test in the increment folder for video 28.

@kentbull
Copy link
Author

kentbull commented Jul 5, 2023

I am able to run tests at the REPL. I run them by sending the forms to the REPL and then running the functions from the REPL.

@jacekschae
Copy link
Owner

How does your system look like at this point? When you evaluate state/system what do you get?

@kentbull
Copy link
Author

kentbull commented Jul 19, 2023

state/system looks like the following, with the jdbc URL redacted:

{:db/postgres #next.jdbc.default_options.DefaultOptions{
    :connectable "jdbc:postgresql://my_heroku_psql_instance_url",
    :options {:qualifier-fn #'camel-snake-kebab.core/->kebab-case,
                    :label-fn #'camel-snake-kebab.core/->kebab-case,
                    :builder-fn #'next.jdbc.result-set/as-kebab-maps,
                    :column-fn #'camel-snake-kebab.core/->snake_case,
                    :table-fn #'camel-snake-kebab.core/->snake_case}},
 :cheffy/app #object[clojure.lang.AFunction$1 0x78d6ec88 "clojure.lang.AFunction$1@78d6ec88"],
 :server/jetty #object[org.eclipse.jetty.server.Server 0x12be30ac "Server@12be30ac{STARTED}[9.4.28.v20200408]"]}

@kentbull
Copy link
Author

Well, that is only when running in the REPL. Are you referring to evaluating state/system from within the lein test call?

@kentbull
Copy link
Author

Well, this does make sense. I have been running tests from the REPL, which is a live running system, and there hasn't been any code written to initialize the application for the Leiningen tests. Maybe this is a non-issue. I can run the tests successfully from within the REPL, just not with lein test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants