Skip to content

Commit c36c985

Browse files
authored
Merge branch 'master' into Runs_CustomAttributesUpdate
2 parents 27d8df3 + 03ea76c commit c36c985

6 files changed

Lines changed: 56 additions & 121 deletions

File tree

README.md

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# practitest-firecracker
22

3-
You will need to use the 'create-testset' action once and the 'populate-testset' action every time there is a new report.
4-
If the structure of the report changes (new tests are added for example), you will need to use the 'create-testset' action again. New TestSets will be created, but existing tests will be reused.
3+
You will need to use the 'create-and-populate-testset' action that will create and populate TestSets, Tests, Instances and Runs.
4+
If the structure of the report changes (new tests are added for example), you will need to use the 'create-and-populate-testset' action again. New TestSets will be created, but existing tests will be reused.
55

66
If you don't have an existing CONFIG_FILE and you want to use it, go to https://firecracker-ui-prod.practitest.com/ and generate one.
77
To login, you can use your PractiTest credentials and follow the instructions in the link. Then you can continue here and set the config-path to your configuration file path.
@@ -23,35 +23,12 @@ java -jar practitest-firecracker-standalone.jar help
2323
```
2424
to get more information about the parameters and commands.
2525

26-
### create-testset
26+
### version
2727

28-
Create new testset from reports folder:
28+
To check your jar version you can you this command:
2929

3030
``` shell
31-
java -jar practitest-firecracker-standalone.jar \
32-
--reports-path=SUREFIRE_REPORTS_PATH \
33-
--testset-name="TestSet name" \
34-
--author-id=PRACTITEST_USER_ID \
35-
--config-path=CONFIG_FILE \
36-
create-testset
37-
```
38-
39-
The call above will analyze the surefire reports and create tests and the testset. If a test already exists, it will be reused.
40-
41-
You can set various custom fields for tests when they are created (especially useful if you have mandatory fields configured in your tests).
42-
43-
To set custom fields you will need to create a configuration file in here: https://firecracker-ui-prod.practitest.com/ .After that you can use it to run the command line above with it (CONFIG_FILE).
44-
45-
### populate-testset
46-
Populate the testset from reports folder:
47-
48-
``` shell
49-
java -jar practitest-firecracker-standalone.jar \
50-
--reports-path=SUREFIRE_REPORTS_PATH \
51-
--testset-id=PRACTITEST_TESTSET_ID \
52-
--author-id=PRACTITEST_USER_ID \
53-
--config-path=CONFIG_FILE \
54-
populate-testset
31+
java -jar practitest-firecracker-standalone.jar version
5532
```
5633

5734
### create-and-populate-testset
@@ -62,19 +39,26 @@ Example:
6239

6340
``` shell
6441
java -jar practitest-firecracker-standalone.jar \
65-
--reports-path=SUREFIRE_REPORTS_PATH \
66-
--testset-name="TestSet name" \
42+
--reports-path=REPORTS_FOLDER_PATH \
6743
--author-id=PRACTITEST_USER_ID \
6844
--config-path=CONFIG_FILE \
6945
create-and-populate-testset
7046
```
71-
* In the future config files --testset-name will be defined inside of the config file so there will be no need to define it in the command line
47+
* author-id is not required in case of PAT (personal api token) is in use
48+
49+
The call above will analyze the surefire reports and create and populate tests and the testset. If a test already exists, it will be reused.
50+
51+
You can set various custom fields for tests when they are created (especially useful if you have mandatory fields configured in your tests).
52+
53+
To set custom fields you will need to create a configuration file in here: https://firecracker-ui-prod.practitest.com/ .After that you can use it to run the command line above with it (CONFIG_FILE).
54+
7255
### use Firecracker without config file
7356

7457
You can use all the above commands without the config file. You will need to explicitly define
7558
parameters:
7659
--api-token=YOUR_API_TOKEN
7760
--email=YOUR_EMAIL
61+
--testset-name=TESTSET_NAME
7862
--project-id=PRACTITEST_PROJECT_ID
7963
--additional-test-fields '{"custom-fields": {"---f-123": "foo", "---f-124": "bar"}, "system-fields"{"version": "2.3", "status":"Draft"}}'
8064
--additional-testset-fields '{"custom-fields": {"---f-125": "baz"}, "system-fields"{"version": "1.0", "assigned-to-id": "1"}}
@@ -83,12 +67,12 @@ if they are relevant to the run (additional-fields not required).
8367

8468

8569
Example:
86-
8770
``` shell
8871
java -jar practitest-firecracker-standalone.jar \
8972
--api-token=YOUR_API_TOKEN \
9073
--email=YOUR_EMAIL \
91-
--reports-path=SUREFIRE_REPORTS_PATH \
74+
--testset-name=TESTSET_NAME \
75+
--reports-path=REPORTS_FOLDER_PATH \
9276
--project-id=PRACTITEST_PROJECT_ID \
9377
--testset-name="TestSet name" \
9478
--author-id=PRACTITEST_USER_ID \
@@ -120,6 +104,11 @@ In case you want the name of the test to take its value from other attribute of
120104

121105
Same goes for --pt-test-step-name that will define the name of the steps.
122106

107+
--multitestset option will point if we are using multitestset file if it is true we will take the testsetname from
108+
the name attribute from inside the file.
109+
110+
--test-case-as-pt-test-step will declare if we want to set testcase as single test or as a group of testcases.
111+
123112
For more information contact our support.
124113

125114
## License

src/practitest_firecracker/cli.clj

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,16 @@
7070
["-h" "--help"]])
7171

7272
(defn usage [options-summary]
73-
(->> ["PractiTest Surefire reports analyzer."
73+
(->> ["PractiTest reports analyzer."
7474
""
7575
"Usage: java -jar practitest-firecracker-standaline.jar [options] action"
7676
""
7777
"Options:"
7878
options-summary
7979
""
8080
"Actions:"
81-
" create-testset Analyzes the given Surefire reports directory and creates a TestSet with Tests and Steps in PractiTest to reflect"
82-
" the structure of the report. Returns a TestSet ID that you should use to run the 'populate-testset' action"
83-
" populate-testset Analyzes the given Surefire reports directory and populates the given TestSet with the data from the report"
84-
" create-and-populate-testset Shortcut to perform both actions. If the TestSet with the given name already exists, it will be reused. If it exists, but has completely different set of tests, an error will be reported."
85-
""]
81+
" create-and-populate-testset Shortcut to perform both actions. If the TestSet with the given name already exists, it will be reused. If it exists, but has completely different set of tests, an error will be reported."
82+
" version Will display firecracker jar file version"]
8683
(string/join \newline)))
8784

8885
(defn error-msg [errors]
@@ -117,48 +114,19 @@
117114
{:exit-message (error-msg errors)}
118115

119116
(= "display-config" (first arguments))
120-
(cond
121-
:else
122-
{:action "display-config" :options options})
117+
{:action "display-config" :options options}
123118

124119
(= "display-options" (first arguments))
125-
(cond
126-
:else
127-
{:action "display-options" :options options})
128-
129-
;; (= "create-testset" (first arguments))
130-
;; (cond
131-
;; (nil? (:project-id options))
132-
;; {:exit-message (missing-option-msg "create-testset" "project-id")}
133-
134-
;; (nil? (:author-id options))
135-
;; {:exit-message (missing-option-msg "create-testset" "author-id")}
136-
137-
;; (nil? (:testset-name options))
138-
;; {:exit-message (missing-option-msg "create-testset" "testset-name")}
120+
{:action "display-options" :options options}
139121

140-
;; :else
141-
;; {:action "create-testset" :options options})
142-
143-
(= "populate-testset" (first arguments))
144-
(cond
145-
(nil? (:project-id options))
146-
{:exit-message (missing-option-msg "populate-testset" "project-id")}
147-
148-
(nil? (:testset-id options))
149-
{:exit-message (missing-option-msg "populate-testset" "testset-id")}
150-
151-
:else
152-
{:action "populate-testset" :options options})
122+
(= "version" (first arguments))
123+
{:action "version" :options options}
153124

154125
(= "create-and-populate-testset" (first arguments))
155126
(cond
156127
(nil? (:project-id options))
157128
{:exit-message (missing-option-msg "create-and-populate-testset" "project-id")}
158129

159-
(nil? (:author-id options))
160-
{:exit-message (missing-option-msg "create-and-populate-testset" "author-id")}
161-
162130
(and (nil? (:testset-name options)) (not (:multitestset options)))
163131
{:exit-message (missing-option-msg "create-and-populate-testset" "testset-name")}
164132

src/practitest_firecracker/core.clj

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,19 @@
33
[practitest-firecracker.cli :refer [parse-args]]
44
[practitest-firecracker.practitest :refer [make-client
55
make-runs
6-
populate-sf-results
76
create-testsets
87
group-tests
98
create-or-update-tests
109
create-instances
11-
create-runs]]
10+
create-runs
11+
fc-version]]
1212
[practitest-firecracker.parser.core :refer [send-directory parse-files]]
13+
[practitest-firecracker.utils :refer [exit]]
1314
[clojure.pprint :as pprint]
1415
[clojure.java.io :refer [file]]
1516
[clj-time.core :as t])
1617
(:gen-class))
1718

18-
(defn exit [status msg]
19-
(println msg)
20-
(System/exit status))
21-
2219
(defmacro timef
2320
[module expr]
2421
`(let [start# (. System (nanoTime))
@@ -33,8 +30,8 @@
3330
(exit (if ok? 0 1) exit-message)
3431
(let [client (make-client (select-keys options [:email :api-token :api-uri :max-api-rate]))
3532
directory (:reports-path options)
36-
dirs (for [dir directory] (clojure.java.io/file dir))
37-
parsed-dirs (for [dir (file-seq (first dirs))] (parse-files dir))
33+
dirs (when-not (nil? directory) (for [dir directory] (clojure.java.io/file dir)))
34+
parsed-dirs (when-not (nil? dirs) (for [dir (file-seq (first dirs))] (parse-files dir)))
3835
additional-reports (send-directory parsed-dirs (:test-case-as-pt-test-step options) (:multitestset options) (:testset-name options) false)
3936
start-time (t/now)]
4037
(case action
@@ -48,26 +45,8 @@
4845
(pprint/pprint {"=============== options: ===============" options})
4946
(pprint/pprint {"=============== args: ===============" args}))
5047

51-
;; "create-testset"
52-
;; (do
53-
;; (doall
54-
;; (pmap
55-
;; (fn [report]
56-
;; (let [testset (create-or-update-sf-testset client options report)]
57-
;; (pprint/pprint (format "Populated TestSet ID: %s" (:id testset)))))
58-
;; additional-reports))
59-
;; (exit 0 "Done"))
60-
61-
"populate-testset"
62-
(do
63-
(doall
64-
(pmap
65-
(fn [report]
66-
(populate-sf-results client
67-
options
68-
report))
69-
additional-reports))
70-
(exit 0 "Done"))
48+
"version"
49+
(println "Version: " fc-version)
7150

7251
"create-and-populate-testset"
7352
(do

src/practitest_firecracker/practitest.clj

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
[clojure.walk :refer [postwalk]]
66
[clj-http.client :as http]
77
[clojure.tools.logging :as log]
8+
[cheshire.core :as json]
89
[practitest-firecracker.query-dsl :refer [query? eval-query]]
910
[throttler.core :refer [fn-throttler]]
10-
[practitest-firecracker.utils :refer [parse-id print-run-time test-need-update?]]
11+
[practitest-firecracker.utils :refer [parse-id print-run-time test-need-update? exit group-errors]]
1112
[clojure.pprint :as pprint]))
1213

1314
;; ===========================================================================
1415
;; api version
15-
(def ^:const fc-version "2.0.2")
16+
(def ^:const fc-version "2.0.4")
1617

1718
;; ===========================================================================
1819
;; utils
@@ -32,9 +33,7 @@
3233
(apply format (str base-uri resource-uri-template) params))
3334

3435
(defn throw-api-exception [ex-info status body uri]
35-
(throw (ex-info "API request failed" {:status status
36-
:body body
37-
:uri uri})))
36+
(exit status (group-errors body)))
3837

3938
(defn api-call [{:keys [credentials uri method query-params form-params]}]
4039
(assert (not (and query-params form-params))
@@ -497,21 +496,6 @@
497496
:attributes run
498497
:steps run-steps}))))))
499498

500-
(defn populate-sf-results [client {:keys [project-id testset-id display-action-logs] :as options} sf-test-suites]
501-
(when display-action-logs (log/infof "populating testset %s with results from %d suites" testset-id (count sf-test-suites)))
502-
(when (or (:skip-validation? options)
503-
(validate-testset client project-id testset-id sf-test-suites))
504-
(doall
505-
(pmap (fn [test-suite]
506-
(let [test-name (sf-test-suite->pt-test-name options test-suite)
507-
log (if display-action-logs (log/infof "instance test-name: %s " test-name) nil)
508-
test (ll-find-test client [project-id display-action-logs] test-name)
509-
instance (ll-find-instance client [project-id display-action-logs] testset-id (:id test))
510-
[run run-steps] (sf-test-suite->run-def options test-suite)]
511-
(ll-create-run client [project-id display-action-logs] (:id instance) run run-steps)))
512-
sf-test-suites))
513-
true))
514-
515499
(defn find-sf-testset [client [project-id display-action-logs] options testset-name]
516500
(let [testset (ll-find-testset client [project-id display-action-logs] testset-name)]
517501
(when testset

src/practitest_firecracker/query_dsl.clj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@
5555
(throw
5656
(ex-info "Syntax error: 'drop-last' must have one or two arguments"
5757
{:query query})))
58+
'take-last (case (count args)
59+
1 (take-last 1 (first args))
60+
2 (take-last (first args) (second args))
61+
(throw
62+
(ex-info "Syntax error: 'take-last' must have one or two arguments"
63+
{:query query})))
5864
'concat (apply str args)
5965
'capitalize (if (= 1 (count args))
6066
(map string/capitalize (first args))

src/practitest_firecracker/utils.clj

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
(ns practitest-firecracker.utils
22
(:require
33
[clj-time.core :as t]
4-
[clojure.pprint :as pprint]))
4+
[clojure.pprint :as pprint]
5+
[clojure.string :as string]
6+
[cheshire.core :as json]))
57

68
(defn print-run-time [text start-time]
79
(let [sec-pass (t/in-seconds (t/interval start-time (t/now)))
@@ -21,3 +23,10 @@
2123
;; :test test})
2224
]
2325
true))
26+
27+
(defn exit [status msg]
28+
(println msg)
29+
(System/exit status))
30+
31+
(defn group-errors [body]
32+
(str "Errors: \n" (string/join "\n" (map #(str "- " %) (map :title (:errors (json/parse-string body true)))))))

0 commit comments

Comments
 (0)