Skip to content

Commit 53d35a0

Browse files
Merge pull request #5 from alekseysotnikov/Test-coverage-not-less-than-75-percentage
#4 Test coverage not less than 75 percentage
2 parents 418391d + a8d0d9d commit 53d35a0

File tree

4 files changed

+162
-45
lines changed

4 files changed

+162
-45
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ After the modifications, Buran can generate from it your own feed, for example i
1515

1616
### Installation
1717

18-
1. Add to *project.clj* - ```[buran "0.1.3"]```
18+
1. Add to *project.clj* - ```[buran "0.1.4"]```
1919

2020
2. Import
2121

project.clj

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,18 @@
1-
(defproject buran "0.1.3"
2-
3-
1+
(defproject buran "0.1.4"
42
:description "Bidirectional, data-driven RSS/Atom feed consumer, producer and feeds aggregator"
5-
6-
73
:url "https://github.com/alekseysotnikov/buran"
8-
9-
104
:license {:name "Apache License 2.0"
115
:url "https://www.apache.org/licenses/LICENSE-2.0.html"}
12-
13-
146
:dependencies [[org.clojure/clojure "1.8.0"]
157
[com.rometools/rome "1.12.0"]]
16-
17-
188
:plugins [[lein-cloverage "1.1.1"]]
19-
20-
21-
:aot :all
22-
23-
249
:profiles {:uberjar {:aot :all}
2510
:linters {:dependencies [[org.clojure/clojure "1.10.0"]
2611
[clj-kondo "2019.07.18-alpha-SNAPSHOT"]]
2712
:plugins [[lein-kibit "0.1.7"]
2813
[jonase/eastwood "0.3.6"]]}}
29-
30-
3114
:deploy-repositories {"clojars" {:url "https://clojars.org/repo"
3215
:sign-releases false}}
33-
34-
3516
:aliases {"deploy" ["deploy" "clojars"]
3617
"kibit" ["with-profile" "+linters" "kibit"]
3718
"eastwood" ["with-profile" "+linters" "eastwood" "{:continue-on-exception true :namespaces [:source-paths]}"]

src/buran/core.clj

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111

1212
(defmacro with-exception [throw? & body]
13-
(if throw?
14-
`(do ~@body)
15-
`(try
16-
~@body
17-
(catch Throwable e#
18-
{:message (.getMessage e#)
19-
:error e#}))))
13+
(list 'if throw?
14+
`(do ~@body)
15+
`(try
16+
~@body
17+
(catch Exception e#
18+
{:message (.getMessage e#)
19+
:error e#}))))
2020

2121

2222
(defn consume
@@ -38,8 +38,11 @@
3838
allow-doctypes false
3939
throw-exception false}}]
4040
(with-exception throw-exception
41-
(let [from (if (string? source) (StringReader. source) from)
42-
from (if (string? from) (File. from) from)
41+
(let [from (if (string? source)
42+
(StringReader. source)
43+
(cond
44+
(fn? from) (from)
45+
(string? from) (StringReader. from)))
4346
consumer (doto
4447
(SyndFeedInput. validate locale)
4548
(.setAllowDoctypes allow-doctypes)
@@ -68,8 +71,7 @@
6871
(let [request (if (string? request)
6972
{:from request}
7073
request)
71-
reader (http-reader request)
72-
request (assoc request :from reader)]
74+
request (assoc request :from #(http-reader request))]
7375
(consume request)))
7476

7577

test/buran/core_test.clj

Lines changed: 147 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,39 @@
11
(ns buran.core-test
22
(:require
33
[buran.core :refer :all]
4-
[clojure.test :refer :all]))
4+
[clojure.test :refer :all])
5+
(:import [java.io ByteArrayInputStream File]))
56

67

78
(def short-feed {:info {:feed-type "atom_1.0"
89
:title "Feed title"}
910
:entries [{:title "Entry title"
1011
:description {:value "entry description"}}]})
1112

13+
1214
(def short-feed-str "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<feed xmlns=\"http://www.w3.org/2005/Atom\">\r\n <title>Feed title</title>\r\n <subtitle />\r\n <entry>\r\n <title>Entry title</title>\r\n <author>\r\n <name />\r\n </author>\r\n <summary>entry description</summary>\r\n </entry>\r\n</feed>\r\n")
1315

1416

1517
(deftest produce-feed
16-
(testing "Producing a feed"
17-
(is (= (produce {:feed short-feed
18-
:pretty-print false})
19-
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<feed xmlns=\"http://www.w3.org/2005/Atom\"><title>Feed title</title><subtitle /><entry><title>Entry title</title><author><name /></author><summary>entry description</summary></entry></feed>\r\n"))))
18+
(let [expected "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<feed xmlns=\"http://www.w3.org/2005/Atom\"><title>Feed title</title><subtitle /><entry><title>Entry title</title><author><name /></author><summary>entry description</summary></entry></feed>\r\n"]
19+
(testing "Produce the feed to various types"
20+
(is (= expected (produce {:feed short-feed
21+
:pretty-print false})))
22+
(is (instance? org.w3c.dom.Document (produce {:feed short-feed
23+
:to :w3cdom})))
24+
(is (instance? org.jdom2.Document (produce {:feed short-feed
25+
:to :jdom}))))
26+
(testing "Produce the feed to a file"
27+
(let [pathname "target/feed.xml"]
28+
(produce {:feed short-feed
29+
:to pathname
30+
:pretty-print false})
31+
(is (= expected (slurp pathname))))
32+
(let [pathname "target/feed2.xml"]
33+
(produce {:feed short-feed
34+
:to (File. pathname)
35+
:pretty-print false})
36+
(is (= expected (slurp pathname)))))))
2037

2138

2239
(deftest produce-pretty-printed-feed
@@ -70,15 +87,132 @@
7087
:description {:value "entry description 2"}}]}))))
7188

7289

90+
(deftest consume-from-string
91+
(is (= short-feed (shrink (consume short-feed-str))))
92+
(is (= short-feed (shrink (consume {:from short-feed-str})))))
93+
94+
95+
(deftest consume-http-test
96+
(testing "from input stream"
97+
(is (= short-feed (shrink (consume-http {:from (ByteArrayInputStream. (.getBytes short-feed-str))}))))))
98+
99+
100+
(deftest negative-consume-http
101+
(let [{:keys [error message]} (consume-http "invalid://url")]
102+
(is (instance? Throwable error))
103+
(is (= "unknown protocol: invalid" message))))
104+
105+
106+
(deftest negative-consume
107+
(testing "throwable"
108+
(is (instance? Throwable (try
109+
(consume {:throw-exception true
110+
:from "<invalid rss>"})
111+
(catch Throwable e
112+
e)))))
113+
(testing "map with an exception"
114+
(let [{:keys [error message]} (consume {:throw-exception false
115+
:from "<invalid rss>"})]
116+
(is (instance? Throwable error))
117+
(is (string? message)))))
118+
119+
73120
(deftest consume-produce-roundtrip
74121
(is (= short-feed (-> short-feed
75122
produce
76123
consume
77-
shrink))
78-
(is (= short-feed-str (-> short-feed-str
79-
consume
80-
shrink
81-
produce)))))
82-
83-
84-
124+
shrink)))
125+
(is (= short-feed-str (-> short-feed-str
126+
consume
127+
shrink
128+
produce))))
129+
130+
131+
(def real-feed '{:info {:description "most recent 30 from stackoverflow.com"
132+
:feed-type "atom_1.0"
133+
:link "https://stackoverflow.com/questions/tagged/?tagnames=clojure&sort=active"
134+
:links ({:href "https://stackoverflow.com/feeds/tag?tagnames=clojure"
135+
:length 0
136+
:rel "self"
137+
:type "application/atom+xml"}
138+
{:href "https://stackoverflow.com/questions/tagged/?tagnames=clojure&sort=active"
139+
:length 0
140+
:rel "alternate"
141+
:type "text/html"})
142+
:published-date #inst "2020-02-22T16:12:21.000-00:00"
143+
:title "Active questions tagged clojure - Stack Overflow"
144+
:uri "https://stackoverflow.com/feeds/tag?tagnames=clojure"}
145+
:entries [{:author "Jim"
146+
:authors ({:name "Jim"
147+
:uri "https://stackoverflow.com/users/5673289"})
148+
:categories ({:name "bidi"
149+
:taxonomy-uri "https://stackoverflow.com/tags"}
150+
{:name "ring"
151+
:taxonomy-uri "https://stackoverflow.com/tags"}
152+
{:name "clojure"
153+
:taxonomy-uri "https://stackoverflow.com/tags"}
154+
{:name "server"
155+
:taxonomy-uri "https://stackoverflow.com/tags"}
156+
{:name "web"
157+
:taxonomy-uri "https://stackoverflow.com/tags"})
158+
:description {:type "html"
159+
:value "I am learning Clojure for the web..."}
160+
:link "https://stackoverflow.com/questions/60234899/simple-web-app-of-bidi-ring-and-lein-gives-a-500-error"
161+
:links ({:href "https://stackoverflow.com/questions/60234899/simple-web-app-of-bidi-ring-and-lein-gives-a-500-error"
162+
:length 0
163+
:rel "alternate"})
164+
:published-date #inst "2020-02-15T00:05:23.000-00:00"
165+
:title "Simple web app of Bidi, Ring and Lein gives a 500 error"
166+
:updated-date #inst "2020-02-15T00:47:32.000-00:00"
167+
:uri "https://stackoverflow.com/q/60234899"}
168+
{:author "Bob"
169+
:authors ({:name "Bob"
170+
:uri "https://stackoverflow.com/users/5440125"})
171+
:categories ({:name "cider"
172+
:taxonomy-uri "https://stackoverflow.com/tags"}
173+
{:name "clojure"
174+
:taxonomy-uri "https://stackoverflow.com/tags"})
175+
:description {:type "html"
176+
:value "The default cider-test-report reporter is ..."}
177+
:link "https://stackoverflow.com/questions/60235197/how-to-use-the-eftest-library-with-cider-test-report"
178+
:links ({:href "https://stackoverflow.com/questions/60235197/how-to-use-the-eftest-library-with-cider-test-report"
179+
:length 0
180+
:rel "alternate"})
181+
:published-date #inst "2020-02-15T01:08:30.000-00:00"
182+
:title "How to use the eftest library with cider-test-report?"
183+
:updated-date #inst "2020-02-15T01:08:30.000-00:00"
184+
:uri "https://stackoverflow.com/q/60235197"}
185+
{:author "Bob"
186+
:authors ({:name "Bob"
187+
:uri "https://stackoverflow.com/users/5440125"})
188+
:categories ({:name "clojure"
189+
:taxonomy-uri "https://stackoverflow.com/tags"}
190+
{:name "regex"
191+
:taxonomy-uri "https://stackoverflow.com/tags"})
192+
:description {:type "html"
193+
:value "Suppose I want to unmap all the namespaces..."}
194+
:link "https://stackoverflow.com/questions/60243053/how-to-return-namespaces-by-regex-in-clojure"
195+
:links ({:href "https://stackoverflow.com/questions/60243053/how-to-return-namespaces-by-regex-in-clojure"
196+
:length 0
197+
:rel "alternate"})
198+
:published-date #inst "2020-02-15T20:56:55.000-00:00"
199+
:title "How to return namespaces by regex in clojure?"
200+
:updated-date #inst "2020-02-15T23:34:26.000-00:00"
201+
:uri "https://stackoverflow.com/q/60243053"}]})
202+
203+
204+
(deftest real-feed-roundtrip
205+
(is (= real-feed (-> real-feed
206+
produce
207+
consume
208+
shrink
209+
produce
210+
consume
211+
shrink))))
212+
213+
214+
(deftest feed-utilities
215+
(is (= 2 (count (:entries (filter-entries #(= "Bob" (:author %)) real-feed)))))
216+
(is (= ["Bob" "Bob" "Jim"] (->> (sort-entries-by :author real-feed)
217+
:entries
218+
(map :author)))))

0 commit comments

Comments
 (0)