|
3 | 3 | [clojure.set :refer [difference]] |
4 | 4 | [clojure.string :as string] |
5 | 5 | [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]] |
7 | 7 | [practitest-firecracker.api :as api] |
8 | 8 | [practitest-firecracker.const :refer [max-test-ids-bucket-size]] |
9 | 9 | [practitest-firecracker.query-dsl :as query-dsl] |
10 | | - [practitest-firecracker.eval :as eval])) |
| 10 | + [practitest-firecracker.eval :as eval] |
| 11 | + [clojure.pprint :as pprint])) |
11 | 12 |
|
12 | 13 | (defn find-sf-testset [client [project-id display-action-logs] options testset-name] |
13 | 14 | (let [testset (api/ll-find-testset client [project-id display-action-logs] testset-name)] |
14 | 15 | (when testset |
15 | 16 | (eval/update-sf-testset client options testset-name testset (read-string (:id testset)))))) |
16 | 17 |
|
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 | | - |
32 | 18 | (defn create-testsets [client {:keys [project-id display-action-logs] :as options} xml] |
33 | 19 | (doall |
34 | 20 | (for [sf-test-suites xml] |
|
54 | 40 | (defn value-get [existing-cases xml-cases] |
55 | 41 | (conj (into [] existing-cases) (into [] xml-cases))) |
56 | 42 |
|
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] |
58 | 50 | (if use-test-step |
59 | 51 | (map |
60 | 52 | (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)))] |
62 | 61 | (assoc-in t |
63 | 62 | [1 :test-cases] |
64 | 63 | (map first |
65 | 64 | (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) |
69 | 88 | old-tests)) |
70 | 89 |
|
71 | 90 | (defn translate-step-attributes [attributes] |
72 | 91 | {:pt-test-step-name (:name attributes) |
73 | | - :description (:description attributes)}) |
| 92 | + :description (:description attributes) |
| 93 | + :position (:position attributes) |
| 94 | + :attributes attributes}) |
74 | 95 |
|
75 | 96 | (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] |
76 | 97 | (let [new-tests (into [] (eval/group-test-names (vals all-tests) options)) |
|
107 | 128 | nil-tests (filter #(nil? (last %)) xml-tests) |
108 | 129 | old-tests (filter #(not (nil? (last %))) xml-tests) |
109 | 130 |
|
110 | | - tests-with-steps (update-steps use-test-step old-tests test-id-to-cases) |
111 | 131 | tests-after (if (seq nil-tests) |
112 | 132 | ;; create missing tests and add them to the testset |
113 | 133 | (let [new-tests (pmap (fn [[test-name test-suite _]] |
|
116 | 136 | new-tests) |
117 | 137 | ()) |
118 | 138 | 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) |
121 | 141 | ;; update existing tests with new values |
122 | 142 | (doall (map (fn [[_ test-suite test]] |
123 | 143 | (when (test-need-update? test-suite test) |
124 | 144 | (eval/update-sf-test client options test-suite test))) |
125 | | - tests-with-steps)) |
| 145 | + old-tests)) |
126 | 146 | (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])) |
128 | 148 |
|
129 | 149 | (defn split-n-filter-instance-params [test pt-instance-params] |
130 | 150 | (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] |
139 | 164 | (when display-action-logs (log/infof "pt-instance-params: %s" pt-instance-params)) |
140 | 165 | (let [all-test-ids (map (fn [test] (:id (last test))) all-tests) |
141 | 166 | testname-test (into {} (map (fn [test] {(first test) test}) all-tests)) |
|
230 | 255 | (into [] |
231 | 256 | (map |
232 | 257 | (fn [test] |
233 | | - (get-in test [:attributes :parameters])) tests))}) |
| 258 | + (conj (get-in test [:attributes :bdd-parameters]) |
| 259 | + (get-in test [:attributes :parameters]))) tests))}) |
234 | 260 | (group-by |
235 | 261 | (fn [inst] |
236 | 262 | (get-in inst [:attributes :name])) |
|
253 | 279 | {test-name |
254 | 280 | (into {} |
255 | 281 | (map (fn [y] |
256 | | - {(keyword (str (first y))) |
| 282 | + {(if (contains? existing-instance test-name) |
| 283 | + (first y) |
| 284 | + (keyword (str (first y)))) |
257 | 285 | (last y)}) |
258 | 286 | 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))))) |
260 | 290 | (keys testname-to-params))) |
261 | 291 |
|
262 | 292 | new-testname-to-params (into {} |
|
266 | 296 | (into [] (difference (set (get new-map test-name)) (set (get existing-instance test-name))))}) |
267 | 297 | (keys new-map))) |
268 | 298 |
|
| 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) |
269 | 301 | make-instances (flatten (api/make-instances missing-instances new-testname-to-params test-id-testname)) |
270 | 302 | test-by-id (group-by (fn [test] (read-string (:id (last test)))) all-tests) |
271 | 303 | new-intstances (flatten (for [instances-part (partition-all 100 (shuffle make-instances))] |
|
277 | 309 |
|
278 | 310 | instance-to-ts-test (group-by (fn [inst] [(:set-id (:attributes inst)) (:test-id (:attributes inst))]) all-intstances)] |
279 | 311 | (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))))) |
281 | 331 |
|
282 | 332 | (defn create-runs [runs client options start-time] |
283 | 333 | (doall (for [runs-part (partition-all 20 (shuffle runs))] |
|
0 commit comments