This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-03-18
Channels
- # admin-announcements (1)
- # aleph (3)
- # beginners (20)
- # boot (9)
- # cider (74)
- # clara (1)
- # cljs-dev (28)
- # cljsrn (15)
- # clojars (32)
- # clojure (149)
- # clojure-dusseldorf (3)
- # clojure-italy (6)
- # clojure-nl (3)
- # clojure-russia (20)
- # clojure-uk (5)
- # clojurescript (133)
- # core-async (2)
- # cursive (19)
- # datomic (24)
- # devcards (1)
- # funcool (100)
- # hoplon (48)
- # keechma (1)
- # kosmos (7)
- # ldnclj (3)
- # leiningen (3)
- # luminus (16)
- # off-topic (8)
- # om (103)
- # onyx (47)
- # pedestal (3)
- # proton (7)
- # re-frame (13)
- # reagent (11)
- # ring-swagger (1)
- # specter (6)
- # testing (12)
- # untangled (24)
- # yada (32)
@thiagofm: you need to re-run whatever mechanism loaded the config file in the first place
nothing to do with cider I'd say
Can anyone recommend resources (blog posts, sample projects, ...) for larger Clojure test suites? I'm struggling to find answers to simple questions like: if I have shared test code, where should that live? Are there any conventions?
@camdez test code is treated the same way non-test code is - have your abstractions in the namespaces under test-source paths and build upon that
@dm3: Thanks. Perhaps I should have been a bit clearer though—I’m not asking how I possibly can, but I’m looking for recommendations. For example, with clojure.test
one tends to mirror the src namespace tree, adding -test
to the end of the namespace name. If I create a file / namespace in my test/
directory with a -test
name, that might defy the convention that -test
files contain tests. If I don’t add a suffix, the namespace might match something in my src
directory. So I thought there might be community conventions.
yeah, most testing tools have their own convention of naming test files, this is probably best looked up in the docs for the test tool (expectations/midje/...). Also the namespaces should not clash if they appear on the same classpath. Don't think I'm aware of any more conventions.
@camdez: In my experience there are two predominant styles of naming test namespaces:
1. app.foo
=> app.foo-test
(the -test
suffix approach)
2. app.foo
=> app.test.foo
(the .test
subnamespace approach)
2 seems to have been popularised by things like the luminus template - however I really dislike this approach... Mainly because the test file name is the same as the apps namespace file - which can be confusing in some editors. And also for purely selfish reasons that the default emacs/projectile jump to test doesn't understand this convention (but does understand the first).
I just wish there was one standard for tooling to target though.
@rickmoynihan: Thanks, Rick. Kinda funny—I totally understand your assessment and tend to use naming style number #1, but I just made an app.test.helpers
namespace to keep that stuff from colliding with the names in my src namespace, and #2 would dovetail more nicely with that.
I’ve started taking notes on Clojure testing practices with an eye towards putting together a short guide when I have more answers.
@camdez: not sure I see how....
But for test helpers with style 1 you just avoid the -test
suffix for things that don't contain test suites.. e.g. helpers can become:
app.test-helpers
@rickmoynihan: Only in that it bundles everything under a common app.test
namespace. Not critical, but it has some nice properties.
I considered the app.test-helpers
name as well, but all things being equal, I would prefer to not have that code in the same folder as the proper tests. ¯\(ツ)/¯ At this point I’m just experimenting and keeping an eye towards reasons to prefer one method over another.
I don't see that as a problem if you have a convention to find them - if it really bothers you, you can always add another source-path e.g src/
test/
and /test-helpers
- or if you don't want to clutter the root directory - set a source path for /test/suite
and test/helpers
and use convention 1
Hey guys, is it possible to call clojure.core/name
in a macro?
(map name [a b])
results in [nil nil]
when seeing output of macroexpand
maybe it's just a repl thing?
@karolmajta Could you post your whole macro?
sure:
(defmacro defoperation [name bindings & body]
(let [requires (map name (filter keyword? bindings))
arguments (filter symbol? bindings)]
`(def ~name
(map->Operation {:name ~name
:requires ~(vec requires)
:arguments ~(vec arguments)
:fn (fn ~(vec (concat requires arguments))
~@body)}))))
ah! sure! thank you
so simple
Maybe because I'm used to something else. In core.test I couldn't find for example somewhere I would specify my test setup & teardown
take a look at user-fixtures
https://clojuredocs.org/clojure.test/use-fixtures
@thiagofm: midje is also a very popular https://github.com/marick/Midje/wiki
@jmayaalv: I'll take a deeper look at it, I saw the project a couple of years ago but ended up going with core.test at the time
has anyone tried https://github.com/jimpil/fudje ?
yes, in ClojureScript I usually go for vanilla cljs.test
true that
also in my opinion midje and similar libraries introduce another DSL to learn and gives you little value when writing tests
in clojure.test
there is also an interensting https://clojure.github.io/clojure/clojure.test-api.html#clojure.test/set-test
that allows you to put tests and code in the same namespace
(I haven't tried myself to see if it is a good idea though)
still not tried to to merge them, I wonder if you have a smoother REPL + test experience (less switching)
Yeah, I understand but the downside of mix things and having bloat files with mixed things...
makes more complicated to reason about your logic on the namespace just because it contains a lot of more stuff no related to solve the problem...
yeah that can be a problem, I agree
great so I will heed your advice and save some time 😄
thanks!
Can anyone give me tips on how to work with things like config files or key pairs (things you don't want in git or the uberjar)? Wanted to use (io/resource "path/to/key.pem") and then supply that path at runtime but I get errors building the uberjar.
This is the project: https://github.com/danielstockton/aaas/tree/master/resources These are the keys I want to remove from git/uberjar.
@danielstockton: if it's in resources, you should only need to (io/resource "pubkey.pem")
and I'd recommend changing your private key now that it's public
Have that: https://github.com/danielstockton/aaas/blob/master/src/aaas/core.clj#L21 Problem is, I wanted to move my keys under a keys directory and then have {:dev {:resource-paths ["keys"]}}. This means that uberjar can't find it and I get Cannot open <nil> as a Reader at this line
@bostonaholic: Of course I will change the private key after I get this working
Pushed the broken version to github with keys directory committed https://github.com/danielstockton/aaas/tree/master/keys
Is the general idea correct, that I should be able to compile this and supply resources at runtime?
io/resource is for finding things you expect to find on the class path
And it should compile without the resource being present during compilation?
it depends, if you can copy and paste each line of your code in to the repl, without the resource, without error, then yes
I assume by compile you mean aot compile? clojure is always compiled to java byte code, regardless of aot compilation or not
any advice on how to achieve what i want? example project that does similar?
so the way aot compilation works, is basically the same as what I said, each form getting pasted in to the repl one by one, the difference is aot compilation saves the class files off to disk too
so if you paste
(def a (println "foo"))
in to the repl, it is going to get compiled, print "foo" and bind the result, nil, to a(defn a [] (println "foo"))
will of course not print "foo" when you paste it in to the repl, it will get compiled and then run, binding a function to aso
(def a (read-in-some-file))
will fail to compile if the file is not present when you paste it in to the replit fails because (read-in-some-file) is being executed immediately, so you want to delay that somehow
i see, would that be idiomatic for this kind of thing?
delay is better than wrapping it in a function?
well, a delay actually does wrap it in a function, but it is like a memoized zero argument function
a cool thing with delay that I figured out recently is that (force x)
forces the delay x and derefs the value, but if the thing forced is not a delay, it just returns the value
I might instead of using a delay, create a function that reads in the keys, call those functions in side new-web-server and pass them around as arguments
delay seems ok to me, thanks for the tips
think you're right, i'll have to pass them around as arguments or i get into trouble
are there any OSS projects for scanning Leiningen dependencies for CVEs? Kind of like brakeman for rails? http://brakemanscanner.org/
I think this would find the java deps: https://www.owasp.org/index.php/OWASP_Dependency_Check
Are there any tricks to using core.match for compiling s-exps to s-exps? I’m currently doing this: https://github.com/RackSec/desdemona/blob/master/src/desdemona/query.clj#L35-L44 and it works fine but I don’t know if maybe I’m missing some nifty utilities or something
@lvh I don’t have an answer for you, but I’d love to subscribe to your newsletter Have a blog post or anything about what you’re doing?
smw: well, I’m giving a talk about it soon but I’m guessing you’re not in Chicago and I’m not sure it’ll be recorded
smw: I’m a principal engineer at Rackspace Managed Security, we have a customer-facing SOC, we’re trying to build what they want that addresses limitations in currently available SOC software
one of the bets we’re making is that in order to be effective we want a) more power to correlate, b) faster feedback
part of that is “OK let’s run the queries both on recent data in the browser and on less recent data on the JVM backend"
in that the SOC analyst boxes can reasonably have 64GB RAM so who cares if firefox’s RSS is 60GB
(barreleye: http://openpowerfoundation.org/blogs/openpower-open-compute-rackspace-barreleye/)
That’s a good point actually; I probably should go through it again and see what’s applicable
(It gets bursty when two dozen different bro sensors suddenly decide to ship a bunch of PCAP in your direction)
the hard part is long term storage, mostly; I have Aaron Sullivan and the OpenCompute/OpenPOWER teams to give me crazy fast CPU/RAM
Ideally we’d store almost all of that long-term; because the other not-so-big bet is that you care about it for both audit logs and training data
but if you’re ingesting 20PB a day it does not take a lot of days to get to a pretty big object store
also, we’re a SOC, so we can’t use the existing infrastructure; all of that data is quite sensitive
but I would also assume that the economies of scale would make it cheaper to scale a large object storage platform than trying to scale something internally.
if an environment needs to be HIPAA/FedRAMP/PCI/whatever compliant unfortunately you can’t dump all of its logs just wherever
smw: scale’s one thing, unfortunately not all compliance requirements are ok with saying “encryption” and have that be the end of it
Hi, I’m very new to Clojure and just started to get my hand dirty when building a client for my RabbitMQ server. I have some trouble getting message from my « data » exchange and « ALERT » queue. Any idea what I’m missing ? http://pastebin.com/LKqXLQDQ ?
Anybody know if any good libraries for analyzing memory usage in a similar way to using criterium to microbenchmark runtime exist? I've updated a function to remove a sort and criterium is showing a likely improvement in performance, but I'm wondering if the refactoring is better or worse memory-wise, which we're sensitive to at the same sizes sort time starts mattering.
Just fixed a couple of option but cannot get the issue: http://pastebin.com/mA8UbAxq any idea ?
@therabidbanana: a Java profiler should give you memory stats. YourKit is best (commercial), VisualVM (free) is adequate for basic stuff.
@lucj06: What are your errors?
@jamesleonis: I do not have errors, but message are not received
@stuartsierra: was hoping something I could play with in the repl - I know ruby has ways to count object allocations (using ObjectSpace), and if Clojure had something similar it'd be possible maybe? In any case, I'll crack it open with VisualVm - thanks!
@lucj06: I can’t find anything obviously wrong 😕
@therabidbanana: Ruby is its own runtime. Clojure's runtime is the JVM. Clojure itself doesn't have any insight into things like object allocation — that's all at the JVM level. So you need JVM tools.
I’d think it would be possible to write something in clojure that gets access to plaform MBeans on the jvm and reports stats.
Does anyone know what the best way to structure a Swagger request in order to include file data and other form data correctly? I haven't found anything useful in the Compojure or Schema docs for something like this
Basically I'm seeking to extend the picture gallery example on the Web Development with Clojure 2nd Ed book