Skip to content

Commit 1fd499f

Browse files
author
shmuelko
committed
no need case-content
1 parent c03a635 commit 1fd499f

5 files changed

Lines changed: 145 additions & 68 deletions

File tree

src/practitest_firecracker/cli.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
(when (:additional-test-fields parsed-json) {:additional-test-fields new-additional-test-fields})
101101
(when (:additional-run-fields parsed-json) {:additional-run-fields new-additional-run-fields})
102102
(when (:pt-test-name parsed-json) {:pt-test-name (read-query (:pt-test-name parsed-json))})
103+
(when (:pt-test-step-description parsed-json) {:pt-test-step-description (read-query (:pt-test-step-description parsed-json))})
103104
(when (:pt-test-step-name parsed-json) {:pt-test-step-name (read-query (:pt-test-step-name parsed-json))}))]
104105
new-parsed-json))
105106

src/practitest_firecracker/eval.clj

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
(ns practitest-firecracker.eval
22
(:require
33
[clojure.string :as string]
4-
[practitest-firecracker.query-dsl :refer [query? eval-query]]
4+
[practitest-firecracker.query-dsl :refer [query? eval-query read-query]]
55
[clojure.walk :refer [postwalk]]
6-
[clojure.tools.logging :as log]
7-
[practitest-firecracker.utils :refer [pformat]]
8-
[practitest-firecracker.api :as api]))
6+
[practitest-firecracker.utils :refer [pformat replace-map replace-keys]]
7+
[practitest-firecracker.api :as api]
8+
[clojure.pprint :as pprint]))
99

1010
(def custom-field-cache (atom {}))
1111

@@ -17,12 +17,17 @@
1717
(let [test-name (eval-query suite (:pt-test-name options))]
1818
(if (string/blank? test-name) "UNNAMED" test-name)))
1919

20+
(defn sf-test-case->pt-step-description [options test-case]
21+
(let [step-name (eval-query test-case (:pt-test-step-description options))]
22+
(if (string/blank? step-name) "UNNAMED" step-name)))
23+
2024
(defn sf-test-case->pt-step-name [options test-case]
2125
(let [step-name (eval-query test-case (:pt-test-step-name options))]
2226
(if (string/blank? step-name) "UNNAMED" step-name)))
2327

2428
(defn sf-test-case->step-def [options test-case]
25-
{:name (sf-test-case->pt-step-name options test-case)})
29+
{:name (sf-test-case->pt-step-name options test-case)
30+
:description (sf-test-case->pt-step-description options test-case)})
2631

2732
(defn sf-test-suite->test-def [options test-suite]
2833
[{:name (sf-test-suite->pt-test-name options test-suite)}
@@ -100,21 +105,27 @@
100105
additional-testset-fields)
101106
(map :id tests))))
102107

103-
(defn sf-test-case->run-step-def [options test-case]
104-
{:name (sf-test-case->pt-step-name options test-case)
105-
:actual-results (str (:failure-message test-case) \newline (:failure-detail test-case))
106-
:status (case (:failure-type test-case)
107-
:failure "FAILED"
108-
:skipped "N/A"
109-
:error "FAILED"
110-
;; will leave error as FAILED for now, will change it after we add the UI changes and add the option of ERROR to Reqirement Test and TestSet table of runs
111-
nil "PASSED"
112-
"NO RUN")
113-
:description (:description test-case)})
114-
115-
(defn sf-test-suite->run-def [options test-suite]
108+
(defn sf-test-case->run-step-def [options params test-case]
109+
(let [description (or (:description test-case) (sf-test-case->pt-step-description options test-case))
110+
new-desc (replace-map description (replace-keys params))]
111+
{:name (if (nil? (:position test-case))
112+
(sf-test-case->pt-step-name options test-case)
113+
(or (:pt-test-step-name test-case)
114+
(sf-test-case->pt-step-name options test-case)))
115+
:description new-desc
116+
:actual-results (str (:failure-message test-case) \newline (:failure-detail test-case))
117+
:status (case (:failure-type test-case)
118+
:failure "FAILED"
119+
:skipped "N/A"
120+
:error "FAILED"
121+
;; will leave error as FAILED for now, will change it after we add the UI changes and add the option of ERROR to Reqirement Test and TestSet table of runs
122+
nil "PASSED"
123+
"NO RUN")}))
124+
125+
(defn sf-test-suite->run-def [options test-suite params]
116126
[{:run-duration (:time-elapsed test-suite)}
117-
(map (partial sf-test-case->run-step-def options) (:test-cases test-suite))])
127+
(map (partial sf-test-case->run-step-def options params)
128+
(sort-by :position (:test-cases test-suite)))])
118129

119130
(defn sf-test-run->run-def [custom-fields run-duration]
120131
{:run-duration (:time-elapsed run-duration),

src/practitest_firecracker/practitest.clj

Lines changed: 90 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,18 @@
33
[clojure.set :refer [difference]]
44
[clojure.string :as string]
55
[clojure.tools.logging :as log]
6-
[practitest-firecracker.utils :refer [print-run-time test-need-update? pformat]]
6+
[practitest-firecracker.utils :refer [print-run-time test-need-update? pformat replace-map replace-keys]]
77
[practitest-firecracker.api :as api]
88
[practitest-firecracker.const :refer [max-test-ids-bucket-size]]
99
[practitest-firecracker.query-dsl :as query-dsl]
10-
[practitest-firecracker.eval :as eval]))
10+
[practitest-firecracker.eval :as eval]
11+
[clojure.pprint :as pprint]))
1112

1213
(defn find-sf-testset [client [project-id display-action-logs] options testset-name]
1314
(let [testset (api/ll-find-testset client [project-id display-action-logs] testset-name)]
1415
(when testset
1516
(eval/update-sf-testset client options testset-name testset (read-string (:id testset))))))
1617

17-
(defn make-runs [[test-by-id instance-to-ts-test] client {:keys [project-id display-action-logs] :as options} start-time]
18-
(when display-action-logs (log/infof "make-runs"))
19-
(flatten (doall
20-
(for [[test-testset instances] instance-to-ts-test]
21-
(for [instance instances]
22-
(let [[ts-id test-id] test-testset
23-
tst (first (get test-by-id test-id))
24-
[run run-steps] (eval/sf-test-suite->run-def options (get tst 1))
25-
additional-run-fields (eval/eval-additional-fields run (:additional-run-fields options))
26-
additional-run-fields (merge additional-run-fields (:system-fields additional-run-fields))
27-
run (eval/sf-test-run->run-def additional-run-fields (get tst 1))]
28-
{:instance-id (:id instance)
29-
:attributes run
30-
:steps run-steps}))))))
31-
3218
(defn create-testsets [client {:keys [project-id display-action-logs] :as options} xml]
3319
(doall
3420
(for [sf-test-suites xml]
@@ -54,23 +40,58 @@
5440
(defn value-get [existing-cases xml-cases]
5541
(conj (into [] existing-cases) (into [] xml-cases)))
5642

57-
(defn update-steps [use-test-step old-tests test-cases]
43+
(defn connect-maps [map1 map2]
44+
(reduce (fn [result key1]
45+
(assoc result key1 [(merge (into {} (map1 key1)) (into {} (map2 key1)))]))
46+
{}
47+
(distinct (into (keys map1) (keys map2)))))
48+
49+
(defn update-steps [use-test-step old-tests test-cases match-step-by options new-map]
5850
(if use-test-step
5951
(map
6052
(fn [t]
61-
(let [test-id (Integer/parseInt (:id (last t)))]
53+
(let [test-id (Integer/parseInt (:id (last t)))
54+
test-name (first t)
55+
params (get new-map test-name)
56+
test-test-cases (get test-cases test-id)
57+
t-test-cases (filter (fn [case]
58+
(if
59+
(:only-failed-steps options)
60+
(not (= "" (:failure-detail case))) true)) (:test-cases (second t)))]
6261
(assoc-in t
6362
[1 :test-cases]
6463
(map first
6564
(map val
66-
(merge-with into
67-
(group-by :pt-test-step-name (:test-cases (second t)))
68-
(group-by :pt-test-step-name (get test-cases test-id)))))))) old-tests)
65+
(let [group-by-test (group-by
66+
(fn [case]
67+
(reduce (fn [p param]
68+
(or p
69+
(replace-map
70+
(if (= match-step-by "description")
71+
(:description case)
72+
(:pt-test-step-name case))
73+
(replace-keys param))))
74+
false params)) test-test-cases)
75+
group-by-t (group-by
76+
(fn [case]
77+
(reduce (fn [p param]
78+
(or p
79+
(replace-map
80+
(if (= match-step-by "description")
81+
(eval/sf-test-case->pt-step-description options case)
82+
(eval/sf-test-case->pt-step-name options case))
83+
(replace-keys param))))
84+
false params)) t-test-cases)]
85+
(connect-maps
86+
group-by-t
87+
group-by-test))))))) old-tests)
6988
old-tests))
7089

7190
(defn translate-step-attributes [attributes]
7291
{:pt-test-step-name (:name attributes)
73-
:description (:description attributes)})
92+
:description (:description attributes)
93+
:position (:position attributes)
94+
:attributes attributes})
7495

7596
(defn create-or-update-tests [[all-tests org-xml-tests testset-id-to-name ts-id-test-name-num-instances] client {:keys [project-id display-action-logs display-run-time use-test-step] :as options} start-time]
7697
(let [new-tests (into [] (eval/group-test-names (vals all-tests) options))
@@ -107,7 +128,6 @@
107128
nil-tests (filter #(nil? (last %)) xml-tests)
108129
old-tests (filter #(not (nil? (last %))) xml-tests)
109130

110-
tests-with-steps (update-steps use-test-step old-tests test-id-to-cases)
111131
tests-after (if (seq nil-tests)
112132
;; create missing tests and add them to the testset
113133
(let [new-tests (pmap (fn [[test-name test-suite _]]
@@ -116,26 +136,31 @@
116136
new-tests)
117137
())
118138
log (if display-run-time (print-run-time "Time - after create instances: %d:%d:%d" start-time) nil)
119-
new-all-tests (concat tests-after tests-with-steps)]
120-
(when (seq tests-with-steps)
139+
new-all-tests (concat tests-after old-tests)]
140+
(when (seq old-tests)
121141
;; update existing tests with new values
122142
(doall (map (fn [[_ test-suite test]]
123143
(when (test-need-update? test-suite test)
124144
(eval/update-sf-test client options test-suite test)))
125-
tests-with-steps))
145+
old-tests))
126146
(when display-run-time (print-run-time "Time - after update tests: %d:%d:%d" start-time)))
127-
[new-all-tests org-xml-tests testset-id-to-name ts-id-test-name-num-instances]))
147+
[new-all-tests org-xml-tests testset-id-to-name ts-id-test-name-num-instances test-id-to-cases tests-after]))
128148

129149
(defn split-n-filter-instance-params [test pt-instance-params]
130150
(into []
131-
(filter not-empty
132-
(string/split
133-
(query-dsl/eval-query
134-
test
135-
(query-dsl/read-query pt-instance-params))
136-
#"\|"))))
137-
138-
(defn create-instances [[all-tests org-xml-tests testset-id-to-name ts-id-test-name-num-instances] client {:keys [project-id display-action-logs display-run-time pt-instance-params] :as options} start-time]
151+
(map
152+
(fn [param]
153+
(string/trim param))
154+
(filter not-empty
155+
(string/split
156+
(query-dsl/eval-query
157+
test
158+
(query-dsl/read-query pt-instance-params))
159+
#"\|")))))
160+
161+
(defn create-instances [[all-tests org-xml-tests testset-id-to-name ts-id-test-name-num-instances test-id-to-cases tests-after]
162+
client
163+
{:keys [project-id display-action-logs display-run-time pt-instance-params use-test-step match-step-by] :as options} start-time]
139164
(when display-action-logs (log/infof "pt-instance-params: %s" pt-instance-params))
140165
(let [all-test-ids (map (fn [test] (:id (last test))) all-tests)
141166
testname-test (into {} (map (fn [test] {(first test) test}) all-tests))
@@ -230,7 +255,8 @@
230255
(into []
231256
(map
232257
(fn [test]
233-
(get-in test [:attributes :parameters])) tests))})
258+
(conj (get-in test [:attributes :bdd-parameters])
259+
(get-in test [:attributes :parameters]))) tests))})
234260
(group-by
235261
(fn [inst]
236262
(get-in inst [:attributes :name]))
@@ -253,10 +279,14 @@
253279
{test-name
254280
(into {}
255281
(map (fn [y]
256-
{(keyword (str (first y)))
282+
{(if (contains? existing-instance test-name)
283+
(first y)
284+
(keyword (str (first y))))
257285
(last y)})
258286
x))})
259-
(get testname-to-params test-name))))
287+
(if (contains? existing-instance test-name)
288+
(get existing-instance test-name)
289+
(get testname-to-params test-name)))))
260290
(keys testname-to-params)))
261291

262292
new-testname-to-params (into {}
@@ -266,6 +296,8 @@
266296
(into [] (difference (set (get new-map test-name)) (set (get existing-instance test-name))))})
267297
(keys new-map)))
268298

299+
tests-with-steps (update-steps use-test-step all-tests test-id-to-cases match-step-by options new-map)
300+
all-tests (concat tests-after tests-with-steps)
269301
make-instances (flatten (api/make-instances missing-instances new-testname-to-params test-id-testname))
270302
test-by-id (group-by (fn [test] (read-string (:id (last test)))) all-tests)
271303
new-intstances (flatten (for [instances-part (partition-all 100 (shuffle make-instances))]
@@ -277,7 +309,25 @@
277309

278310
instance-to-ts-test (group-by (fn [inst] [(:set-id (:attributes inst)) (:test-id (:attributes inst))]) all-intstances)]
279311
(when display-run-time (print-run-time "Time - after create instances: %d:%d:%d" start-time))
280-
[test-by-id instance-to-ts-test]))
312+
[test-by-id instance-to-ts-test new-map]))
313+
314+
(defn make-runs [[test-by-id instance-to-ts-test new-map] client {:keys [project-id display-action-logs] :as options} start-time]
315+
(when display-action-logs (log/infof "make-runs"))
316+
(flatten (doall
317+
(for [[test-testset instances] instance-to-ts-test]
318+
(map-indexed
319+
(fn [index instance]
320+
(let [[ts-id test-id] test-testset
321+
tst (first (get test-by-id test-id))
322+
params (get new-map (get tst 0))
323+
this-param (get params index)
324+
[run run-steps] (eval/sf-test-suite->run-def options (get tst 1) this-param)
325+
additional-run-fields (eval/eval-additional-fields run (:additional-run-fields options))
326+
additional-run-fields (merge additional-run-fields (:system-fields additional-run-fields))
327+
run (eval/sf-test-run->run-def additional-run-fields (get tst 1))]
328+
{:instance-id (:id instance)
329+
:attributes run
330+
:steps run-steps})) instances)))))
281331

282332
(defn create-runs [runs client options start-time]
283333
(doall (for [runs-part (partition-all 20 (shuffle runs))]

src/practitest_firecracker/query_dsl.cljc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@
119119
query))]
120120
(if (not (or (number? query)
121121
(string? query)
122-
(double? query)))
122+
(double? query)
123+
(nil? query)))
123124
(with-meta (compiler query)
124125
{:query true})
125126
(compiler query))))

src/practitest_firecracker/utils.clj

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
(ns practitest-firecracker.utils
22
(:require
3-
[clj-time.core :as t]
4-
[clojure.pprint :as pprint]
5-
[clojure.string :as string]
6-
[cheshire.core :as json]))
3+
[clj-time.core :as t]
4+
[clojure.pprint :as pprint]
5+
[clojure.string :as string]
6+
[cheshire.core :as json]))
77

88
(defn print-run-time [text start-time]
9-
(let [sec-pass (t/in-seconds (t/interval start-time (t/now)))
10-
secs (mod 60 (t/in-seconds (t/interval start-time (t/now))))
11-
minutes (if (> sec-pass 60) (mod 60 (t/in-minutes (t/interval start-time (t/now)))) 0)
12-
hours (if (> sec-pass 3600) (t/in-hours (t/interval start-time (t/now))) 0)]
9+
(let [sec-pass (t/in-seconds (t/interval start-time (t/now)))
10+
secs (mod 60 (t/in-seconds (t/interval start-time (t/now))))
11+
minutes (if (> sec-pass 60) (mod 60 (t/in-minutes (t/interval start-time (t/now)))) 0)
12+
hours (if (> sec-pass 3600) (t/in-hours (t/interval start-time (t/now))) 0)]
1313
(pprint/pprint (format text hours minutes secs))))
1414

1515
(defn test-need-update? [test-suite test]
@@ -30,3 +30,17 @@
3030
(with-out-str
3131
(apply pprint/pprint args)))
3232

33+
(defn replace-map
34+
[string values-map]
35+
(when (and string (not (empty? (filter #(not (nil? (first %))) values-map))))
36+
(string/replace string
37+
(re-pattern
38+
(apply str
39+
(interpose "|"
40+
(map #(java.util.regex.Pattern/quote %)
41+
(keys values-map)))))
42+
(filter #(not (nil? (first %))) values-map))))
43+
44+
(defn replace-keys [params]
45+
(when params
46+
(into {} (map (fn [[x y]] {(when x (str "<" (name x) ">")) y}) params))))

0 commit comments

Comments
 (0)