Skip to content

Commit 03ea76c

Browse files
authored
Merge pull request #16 from PractiTest/support-PAT-without-author-id
support run without author-id and display better error messages
2 parents 6ca702b + 9a8d832 commit 03ea76c

File tree

6 files changed

+58
-123
lines changed

6 files changed

+58
-123
lines changed

README.md

Lines changed: 24 additions & 35 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,32 +39,39 @@ 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
79-
--additional-test-fields '{"custom-fields": {"---f-123": "foo", "---f-124": "bar"}, "system-fields"{"version": "2.3", "status":"Draft"}}'
80-
--additional-testset-fields '{"custom-fields": {"---f-125": "baz"}, "system-fields"{"version": "1.0", "assigned-to-id": "1"}}
63+
--additional-test-fields='{"custom-fields": {"---f-123": "foo", "---f-124": "bar"}, "system-fields"{"version": "2.3", "status":"Draft"}}'
64+
--additional-testset-fields='{"custom-fields": {"---f-125": "baz"}, "system-fields"{"version": "1.0", "assigned-to-id": "1"}}
8165
if they are relevant to the run (additional-fields not required).
8266

8367

8468
Example:
85-
8669
``` shell
8770
java -jar practitest-firecracker-standalone.jar \
8871
--api-token=YOUR_API_TOKEN \
8972
--email=YOUR_EMAIL \
90-
--reports-path=SUREFIRE_REPORTS_PATH \
73+
--testset-name=TESTSET_NAME \
74+
--reports-path=REPORTS_FOLDER_PATH \
9175
--project-id=PRACTITEST_PROJECT_ID \
9276
--testset-name="TestSet name" \
9377
--author-id=PRACTITEST_USER_ID \
@@ -118,6 +102,11 @@ In case you want the name of the test to take its value from other attribute of
118102

119103
Same goes for --pt-test-step-name that will define the name of the steps.
120104

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

123112
## License

src/practitest_firecracker/cli.clj

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

6868
(defn usage [options-summary]
69-
(->> ["PractiTest Surefire reports analyzer."
69+
(->> ["PractiTest reports analyzer."
7070
""
7171
"Usage: java -jar practitest-firecracker-standaline.jar [options] action"
7272
""
7373
"Options:"
7474
options-summary
7575
""
7676
"Actions:"
77-
" create-testset Analyzes the given Surefire reports directory and creates a TestSet with Tests and Steps in PractiTest to reflect"
78-
" the structure of the report. Returns a TestSet ID that you should use to run the 'populate-testset' action"
79-
" populate-testset Analyzes the given Surefire reports directory and populates the given TestSet with the data from the report"
80-
" 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."
81-
""]
77+
" 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."
78+
" version Will display firecracker jar file version"]
8279
(string/join \newline)))
8380

8481
(defn error-msg [errors]
@@ -111,48 +108,19 @@
111108
{:exit-message (error-msg errors)}
112109

113110
(= "display-config" (first arguments))
114-
(cond
115-
:else
116-
{:action "display-config" :options options})
111+
{:action "display-config" :options options}
117112

118113
(= "display-options" (first arguments))
119-
(cond
120-
:else
121-
{:action "display-options" :options options})
122-
123-
;; (= "create-testset" (first arguments))
124-
;; (cond
125-
;; (nil? (:project-id options))
126-
;; {:exit-message (missing-option-msg "create-testset" "project-id")}
127-
128-
;; (nil? (:author-id options))
129-
;; {:exit-message (missing-option-msg "create-testset" "author-id")}
130-
131-
;; (nil? (:testset-name options))
132-
;; {:exit-message (missing-option-msg "create-testset" "testset-name")}
114+
{:action "display-options" :options options}
133115

134-
;; :else
135-
;; {:action "create-testset" :options options})
136-
137-
(= "populate-testset" (first arguments))
138-
(cond
139-
(nil? (:project-id options))
140-
{:exit-message (missing-option-msg "populate-testset" "project-id")}
141-
142-
(nil? (:testset-id options))
143-
{:exit-message (missing-option-msg "populate-testset" "testset-id")}
144-
145-
:else
146-
{:action "populate-testset" :options options})
116+
(= "version" (first arguments))
117+
{:action "version" :options options}
147118

148119
(= "create-and-populate-testset" (first arguments))
149120
(cond
150121
(nil? (:project-id options))
151122
{:exit-message (missing-option-msg "create-and-populate-testset" "project-id")}
152123

153-
(nil? (:author-id options))
154-
{:exit-message (missing-option-msg "create-and-populate-testset" "author-id")}
155-
156124
(and (nil? (:testset-name options)) (not (:multitestset options)))
157125
{:exit-message (missing-option-msg "create-and-populate-testset" "testset-name")}
158126

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))
@@ -490,21 +489,6 @@
490489
:attributes run
491490
:steps run-steps}))))))
492491

493-
(defn populate-sf-results [client {:keys [project-id testset-id display-action-logs] :as options} sf-test-suites]
494-
(when display-action-logs (log/infof "populating testset %s with results from %d suites" testset-id (count sf-test-suites)))
495-
(when (or (:skip-validation? options)
496-
(validate-testset client project-id testset-id sf-test-suites))
497-
(doall
498-
(pmap (fn [test-suite]
499-
(let [test-name (sf-test-suite->pt-test-name options test-suite)
500-
log (if display-action-logs (log/infof "instance test-name: %s " test-name) nil)
501-
test (ll-find-test client [project-id display-action-logs] test-name)
502-
instance (ll-find-instance client [project-id display-action-logs] testset-id (:id test))
503-
[run run-steps] (sf-test-suite->run-def options test-suite)]
504-
(ll-create-run client [project-id display-action-logs] (:id instance) run run-steps)))
505-
sf-test-suites))
506-
true))
507-
508492
(defn find-sf-testset [client [project-id display-action-logs] options testset-name]
509493
(let [testset (ll-find-testset client [project-id display-action-logs] testset-name)]
510494
(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)