newman_scenario 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +61 -0
- data/LICENSE.txt +21 -0
- data/README.md +117 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/newman_scenario +5 -0
- data/bin/rspec +2 -0
- data/bin/setup +8 -0
- data/lib/newman_scenario.rb +6 -0
- data/lib/newman_scenario/cli.rb +18 -0
- data/lib/newman_scenario/scenario.rb +188 -0
- data/lib/newman_scenario/version.rb +3 -0
- data/newman_scenario.gemspec +46 -0
- metadata +171 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: d60c8eac8bd0c964e9e3b8de49d4ef6c1f9d01dd74b8a06b4e09f30b5ab52c25
|
|
4
|
+
data.tar.gz: 4556d9ae5231ef5ff852f2efebbf3f931115ee0a2624d01733c4b83b494efba5
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 2e8f88228bc646bf1a3f6f0f18aa7834f17a60c7b0fdc2eabc6ad47f1165bc8757bf4b450ef0a2308c913bfe9e7cb4a912115cb1099c8cb64ba0938edd10dbb5
|
|
7
|
+
data.tar.gz: 61c3fd0c42f480b401e33864fe3ce2edc643657ea323f9c9085e7bc6877dd51dc31f5f43567dbdac76553d1a9e0eef4ebc1406762a9ffff26056e8662c9c5b07
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at hugues@xdev.fr. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
newman_scenario (0.1.0)
|
|
5
|
+
dotenv (= 2.7.5)
|
|
6
|
+
httparty (= 0.16.2)
|
|
7
|
+
thor (= 1.0.1)
|
|
8
|
+
tty-prompt (= 0.19.0)
|
|
9
|
+
|
|
10
|
+
GEM
|
|
11
|
+
remote: https://rubygems.org/
|
|
12
|
+
specs:
|
|
13
|
+
diff-lcs (1.3)
|
|
14
|
+
dotenv (2.7.5)
|
|
15
|
+
equatable (0.6.1)
|
|
16
|
+
httparty (0.16.2)
|
|
17
|
+
multi_xml (>= 0.5.2)
|
|
18
|
+
multi_xml (0.6.0)
|
|
19
|
+
necromancer (0.5.1)
|
|
20
|
+
pastel (0.7.3)
|
|
21
|
+
equatable (~> 0.6)
|
|
22
|
+
tty-color (~> 0.5)
|
|
23
|
+
rake (10.5.0)
|
|
24
|
+
rspec (3.9.0)
|
|
25
|
+
rspec-core (~> 3.9.0)
|
|
26
|
+
rspec-expectations (~> 3.9.0)
|
|
27
|
+
rspec-mocks (~> 3.9.0)
|
|
28
|
+
rspec-core (3.9.1)
|
|
29
|
+
rspec-support (~> 3.9.1)
|
|
30
|
+
rspec-expectations (3.9.1)
|
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
32
|
+
rspec-support (~> 3.9.0)
|
|
33
|
+
rspec-mocks (3.9.1)
|
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
35
|
+
rspec-support (~> 3.9.0)
|
|
36
|
+
rspec-support (3.9.2)
|
|
37
|
+
thor (1.0.1)
|
|
38
|
+
tty-color (0.5.1)
|
|
39
|
+
tty-cursor (0.7.1)
|
|
40
|
+
tty-prompt (0.19.0)
|
|
41
|
+
necromancer (~> 0.5.0)
|
|
42
|
+
pastel (~> 0.7.0)
|
|
43
|
+
tty-reader (~> 0.6.0)
|
|
44
|
+
tty-reader (0.6.0)
|
|
45
|
+
tty-cursor (~> 0.7)
|
|
46
|
+
tty-screen (~> 0.7)
|
|
47
|
+
wisper (~> 2.0.0)
|
|
48
|
+
tty-screen (0.7.1)
|
|
49
|
+
wisper (2.0.1)
|
|
50
|
+
|
|
51
|
+
PLATFORMS
|
|
52
|
+
ruby
|
|
53
|
+
|
|
54
|
+
DEPENDENCIES
|
|
55
|
+
bundler (~> 2.0)
|
|
56
|
+
newman_scenario!
|
|
57
|
+
rake (~> 10.0)
|
|
58
|
+
rspec (~> 3.0)
|
|
59
|
+
|
|
60
|
+
BUNDLED WITH
|
|
61
|
+
2.0.2
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Hugues Bernet-Rollande
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# NewmanScenario
|
|
2
|
+
|
|
3
|
+
[Newman](https://github.com/postmanlabs/newman) is a command line utility to run [Postman](https://www.postman.com) request(s).
|
|
4
|
+
It supports:
|
|
5
|
+
- loading a Postman environment file against the requests.
|
|
6
|
+
- running a "folder" of requests
|
|
7
|
+
|
|
8
|
+
This is great, but if you want to perform the same request in multiple "folder", you
|
|
9
|
+
will end up duplicating this requests, which make it hard to maintain.
|
|
10
|
+
|
|
11
|
+
Also, it can be clumbersome to add new "scenario" ("folder") from Postman.
|
|
12
|
+
|
|
13
|
+
Here comes `NewmanScenario`.
|
|
14
|
+
|
|
15
|
+
It basically allow you to cherry pick some requests to be chained, saved them, and run
|
|
16
|
+
the newly created "scenario".
|
|
17
|
+
|
|
18
|
+
The newly builded scenarios are just a list of requests, store in a json format file.
|
|
19
|
+
The file is store in the current working directory under `newman_scenarios.json`
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
Add this line to your application's Gemfile:
|
|
25
|
+
|
|
26
|
+
```ruby
|
|
27
|
+
gem 'newman_scenario'
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
And then execute:
|
|
31
|
+
|
|
32
|
+
$ bundle
|
|
33
|
+
|
|
34
|
+
Or install it yourself as:
|
|
35
|
+
|
|
36
|
+
$ gem install newman_scenario
|
|
37
|
+
|
|
38
|
+
## Configuration
|
|
39
|
+
|
|
40
|
+
Add this to your `ENV` or `.env`
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
POSTMAN_API_KEY: POSTMAN_API_KEY (https://YOURPOSTMAN.postman.co/settings/me/api-keys)
|
|
44
|
+
# postman environments ids (extract from) in json format
|
|
45
|
+
NEWMAN_SCENARIO_ENVIRONMENTS: {"staging1": "7361507-b4fcda81-db77-0000-AAAA-XXXXXX","staging3": "7361507-5f29f2c7-efff-0000-AAAA-XXXXX","staging5": "7361507-f360c483-6277-0000-AAAA-XXXXX","local": "2d98e3c9-27dc-0000-AAAA-XXXXX"}
|
|
46
|
+
# postman collection id (extract from)
|
|
47
|
+
NEWMAN_SCENARIO_COLLECTION_ID: 7361507-9627fa69-1fe0-0000-AAAA-XXXXXX
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Rails App
|
|
51
|
+
|
|
52
|
+
```ruby
|
|
53
|
+
# config/initializers/newman_scenario.rb
|
|
54
|
+
require 'newman_scenario'
|
|
55
|
+
|
|
56
|
+
# NewmanScenario configuration
|
|
57
|
+
NewmanScenario::Scenario.default_collection_id = 'ABCDEF-XXXXX-XXXX-0000-AAAA-XXXXXX' # ENV['NEWMAN_SCENARIO_COLLECTION_ID']
|
|
58
|
+
NewmanScenario::Scenario.default_environment_ids = { staging: 'YXZ-XXXXX-XXXX-0000-AAAA-XXXXXX', production: ''ABC-XXXXX-XXXX-0000-AAAA-XXXXXX''} # ENV['NEWMAN_SCENARIO_ENVIRONMENTS'] (json format)
|
|
59
|
+
NewmanScenario::Scenario.default_collection_id = 'PMAK-XXXX-XXXX' # ENV['POSTMAN_API_KEY']
|
|
60
|
+
NewmanScenario::Scenario.default_custom_collection_file_path = 'newman-scenarios.json' # ENV['NEWMAN_SCENARIO_CUSTOM_COLLECTION_FILE_PATH'], default: `newman_scenarios.json`
|
|
61
|
+
NewmanScenario::Scenario.default_last_scenario_file_path = 'newman-scenarios.json' # ENV['NEWMAN_SCENARIO_LAST_SCENARIO_FILE_PATH'], default: `last_newman_scenario.json`
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Usage
|
|
65
|
+
|
|
66
|
+
`NewmanScenario` can be use a stand-alone or within a (Rails) App.
|
|
67
|
+
|
|
68
|
+
### Stand alone
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
# will prompt you to select a environment (by it's name, see configuration)
|
|
72
|
+
# and create or re-use a `NewmanScenario`
|
|
73
|
+
# newly created scenario can be saved
|
|
74
|
+
newman_scenario
|
|
75
|
+
|
|
76
|
+
# will run the previous created scenario 'Signup' against staging3 environment (with no extra prompt)
|
|
77
|
+
newman_scenario staging3 Signup
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Within App
|
|
81
|
+
|
|
82
|
+
```ruby
|
|
83
|
+
require 'newman_scenario'
|
|
84
|
+
|
|
85
|
+
# will run the previous created scenario 'Signup' against staging3 environment (with no extra prompt)
|
|
86
|
+
NewmanScenario::Scenario.new.run(scenario_name: 'Signup', environment_name: 'staging3', no_prompt: true)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
```ruby
|
|
90
|
+
require 'newman_scenario'
|
|
91
|
+
|
|
92
|
+
# will prompt you to select a environment (by it's name, see configuration)
|
|
93
|
+
# and create or re-use a `NewmanScenario`
|
|
94
|
+
# newly created scenario can be saved
|
|
95
|
+
NewmanScenario::Scenario.new.run
|
|
96
|
+
|
|
97
|
+
# will run the previous created scenario 'Signup' against staging3 environment (with no extra prompt)
|
|
98
|
+
NewmanScenario::Scenario.new.run(scenario_name: 'Signup', environment_name: 'staging3', no_prompt: true)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Development
|
|
102
|
+
|
|
103
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
104
|
+
|
|
105
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
106
|
+
|
|
107
|
+
## Contributing
|
|
108
|
+
|
|
109
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/huguesbr/newman_scenario. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
110
|
+
|
|
111
|
+
## License
|
|
112
|
+
|
|
113
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
114
|
+
|
|
115
|
+
## Code of Conduct
|
|
116
|
+
|
|
117
|
+
Everyone interacting in the `NewmanScenario` project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/huguesbr/newman_scenario/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "newman_scenario"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/newman_scenario
ADDED
data/bin/rspec
ADDED
data/bin/setup
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'thor'
|
|
2
|
+
|
|
3
|
+
module NewmanScenario
|
|
4
|
+
class CLI < Thor
|
|
5
|
+
desc "run_scenario environment scenario", "Run scenario using environment"
|
|
6
|
+
long_desc <<~EOF
|
|
7
|
+
|
|
8
|
+
`run_scenario environment scenario` will run the custom saved scenario "scenario"
|
|
9
|
+
using postman environment "environment"
|
|
10
|
+
|
|
11
|
+
`run_scenario` will prompt for the postman environment to use and create or re-used an existing scenario
|
|
12
|
+
EOF
|
|
13
|
+
option :bail
|
|
14
|
+
def run_scenario( environment = nil, scenario = nil )
|
|
15
|
+
Scenario.new.run(scenario_name: scenario, environment_name: environment, bail: options[:bail])
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
require 'tty-prompt'
|
|
2
|
+
require 'json'
|
|
3
|
+
require 'httparty'
|
|
4
|
+
require 'dotenv/load'
|
|
5
|
+
|
|
6
|
+
module NewmanScenario
|
|
7
|
+
class Error < StandardError; end
|
|
8
|
+
|
|
9
|
+
class Scenario
|
|
10
|
+
@default_collection_id = ENV['NEWMAN_SCENARIO_COLLECTION_ID']
|
|
11
|
+
@default_environment_ids = nil
|
|
12
|
+
@default_api_key = ENV['POSTMAN_API_KEY']
|
|
13
|
+
@default_custom_collection_file_path = ENV['NEWMAN_SCENARIO_CUSTOM_COLLECTION_FILE_PATH'] || 'newman_scenarios.json'.freeze
|
|
14
|
+
@default_last_scenario_file_path = ENV['NEWMAN_SCENARIO_LAST_SCENARIO_FILE_PATH'] || '/tmp/last_newman_scenario.json'.freeze
|
|
15
|
+
|
|
16
|
+
class << self
|
|
17
|
+
attr_accessor :default_collection_id
|
|
18
|
+
attr_accessor :default_environment_ids
|
|
19
|
+
attr_accessor :default_api_key
|
|
20
|
+
attr_accessor :default_custom_collection_file_path
|
|
21
|
+
attr_accessor :default_last_scenario_file_path
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
attr_accessor :collection_id
|
|
25
|
+
attr_accessor :environment_ids
|
|
26
|
+
attr_accessor :api_key
|
|
27
|
+
attr_accessor :custom_collection_file_path
|
|
28
|
+
attr_accessor :last_scenario_file_path
|
|
29
|
+
|
|
30
|
+
def initialize(collection_id: nil, environment_ids: nil, api_key: nil, custom_collection_file_path: nil, last_scenario_file_path: nil)
|
|
31
|
+
self.collection_id ||= self.class.default_collection_id
|
|
32
|
+
raise Error, 'Missing Collection Id' unless self.collection_id
|
|
33
|
+
|
|
34
|
+
self.environment_ids ||= self.class.default_environment_ids
|
|
35
|
+
self.environment_ids ||= JSON.parse(ENV['NEWMAN_SCENARIO_ENVIRONMENTS'], symbolize_names: true) if ENV['NEWMAN_SCENARIO_ENVIRONMENTS']
|
|
36
|
+
raise Error, 'Missing Environment Ids' unless self.environment_ids
|
|
37
|
+
|
|
38
|
+
self.api_key ||= self.class.default_api_key
|
|
39
|
+
raise Error, 'Missing Postman API Key' unless self.api_key
|
|
40
|
+
|
|
41
|
+
self.custom_collection_file_path ||= self.class.default_custom_collection_file_path
|
|
42
|
+
raise Error, 'Missing Custom collection file path' unless self.custom_collection_file_path
|
|
43
|
+
|
|
44
|
+
self.last_scenario_file_path ||= self.class.default_last_scenario_file_path
|
|
45
|
+
raise Error, 'Missing Last scenario file path' unless self.last_scenario_file_path
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def run(environment_name: nil, scenario_name: nil, bail: true, no_prompt: false)
|
|
50
|
+
return if `which newman`.empty? && !prompt_to_install_newman
|
|
51
|
+
prompt_to_set_api_key unless api_key
|
|
52
|
+
environment = environment_ids[environment_name.to_sym] if environment_name
|
|
53
|
+
environment ||= prompt.select("Environment", environment_ids, default: 1)
|
|
54
|
+
load_postman_environment(environment, no_prompt: no_prompt)
|
|
55
|
+
collection = JSON.parse(File.read("/tmp/postman-collection-#{collection_id}.json"), symbolize_names: true)[:collection]
|
|
56
|
+
unless File.exist?(last_scenario_file_path) && (!scenario_name && prompt.yes?('Replay last scenario?'))
|
|
57
|
+
scenarii = read_from_json_file(custom_collection_file_path) || {}
|
|
58
|
+
scenario_name ||= prompt.select('Scenario', ['Custom Scenario'] + scenarii.keys.sort)
|
|
59
|
+
scenario_requests = (scenario_name == 'Custom Scenario' && []) || scenarii[scenario_name]
|
|
60
|
+
if scenario_requests.empty?
|
|
61
|
+
scenario_requests = []
|
|
62
|
+
extract_all_requests = lambda do |item, prefix|
|
|
63
|
+
request_name = "#{prefix.empty? ? '' : "#{prefix}/" }#{item[:name]}"
|
|
64
|
+
request_names = [request_name] + (item[:item]&.map { |child_item| extract_all_requests.call(child_item, request_name) } || [])
|
|
65
|
+
request_names
|
|
66
|
+
end
|
|
67
|
+
all_request_names = extract_all_requests.call(collection, '')
|
|
68
|
+
loop do
|
|
69
|
+
scenario_requests.delete('duplicate')
|
|
70
|
+
scenario_requests += prompt.multi_select("Requests (type to filter prefix, choose duplicate to perform action multiple times)", ['duplicate'] + all_request_names, cycle: true, filter: true)
|
|
71
|
+
break unless scenario_requests.include?('duplicate')
|
|
72
|
+
end
|
|
73
|
+
if prompt.yes?('Save this custom scenario?')
|
|
74
|
+
name = prompt.ask('Name?')
|
|
75
|
+
new_or_overwrite = !scenarii.key?(name) || !prompt.no?('This scenario exist, overwrite it?')
|
|
76
|
+
if new_or_overwrite
|
|
77
|
+
prompt.ok "Adding/Updating #{name} to scenarii"
|
|
78
|
+
scenarii[name] = scenario_requests
|
|
79
|
+
write_to_json_file(custom_collection_file_path, scenarii, pretty: true)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
find_request = lambda do |request_path, items|
|
|
84
|
+
item = items.find { |i| i[:name] == request_path.last }
|
|
85
|
+
if item
|
|
86
|
+
item
|
|
87
|
+
else
|
|
88
|
+
child_item = items.find { |i| i[:name] == request_path.first }
|
|
89
|
+
if child_item
|
|
90
|
+
request_path = request_path.drop(1)
|
|
91
|
+
if request_path.empty?
|
|
92
|
+
child_item
|
|
93
|
+
else
|
|
94
|
+
find_request.call(request_path, child_item[:item])
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
requests = scenario_requests.map do |scenario_request|
|
|
100
|
+
find_request.call(scenario_request.split('/'), collection[:item])
|
|
101
|
+
end
|
|
102
|
+
new_collection = {
|
|
103
|
+
collection: {
|
|
104
|
+
info: {
|
|
105
|
+
name: scenario_name,
|
|
106
|
+
schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json'
|
|
107
|
+
},
|
|
108
|
+
item: requests
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
write_to_json_file(last_scenario_file_path, new_collection)
|
|
112
|
+
end
|
|
113
|
+
cmd("newman run #{last_scenario_file_path} -e /tmp/postman-environment-#{environment}.json#{bail ? ' --bail' : ''}")
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
private
|
|
117
|
+
|
|
118
|
+
def cmd(command)
|
|
119
|
+
prompt.ok "Running: #{command}"
|
|
120
|
+
`#{command}`
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def prompt
|
|
124
|
+
@prompt ||= TTY::Prompt.new
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def prompt_to_install_newman
|
|
128
|
+
prompt.warn 'missing newman command line'
|
|
129
|
+
return false unless prompt.yes?('Install newman?')
|
|
130
|
+
prompt.ok 'installing newman: brew install newman'
|
|
131
|
+
cmd('brew install newman')
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def prompt_to_set_api_key
|
|
135
|
+
prompt.warn 'Missing Postman API Key'
|
|
136
|
+
prompt.warn 'Get one from: https://YOURPOSTMAN.postman.co/settings/me/api-keys'
|
|
137
|
+
self.api_key = prompt.ask('Postman API Key')
|
|
138
|
+
cmd("echo \"POSTMAN_API_KEY: #{self.api_key}\" >> .env")
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def load_postman_environment(environment, no_prompt: false)
|
|
142
|
+
reload =
|
|
143
|
+
if no_prompt
|
|
144
|
+
false
|
|
145
|
+
else
|
|
146
|
+
!prompt.no?("Refetch postman config?")
|
|
147
|
+
end
|
|
148
|
+
if File.file?("/tmp/postman-environment-#{environment}.json") && !reload
|
|
149
|
+
prompt.ok "reusing env /tmp/postman-environment-#{environment}.json"
|
|
150
|
+
else
|
|
151
|
+
prompt.ok "fetching environment #{environment}"
|
|
152
|
+
fetch_postman_to_file("/environments/#{environment}", "/tmp/postman-environment-#{environment}.json")
|
|
153
|
+
end
|
|
154
|
+
if File.file?('/tmp/postman-collection.json') && !reload
|
|
155
|
+
prompt.ok "reusing collection /tmp/postman-collection.json"
|
|
156
|
+
else
|
|
157
|
+
prompt.ok "fetching collection #{collection_id}"
|
|
158
|
+
fetch_postman_to_file("/collections/#{collection_id}", "/tmp/postman-collection-#{collection_id}.json")
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def fetch_postman_to_file(url_path, file_path)
|
|
163
|
+
puts "https://api.getpostman.com/#{url_path}"
|
|
164
|
+
response = HTTParty.get("https://api.getpostman.com/#{url_path}", headers: { 'X-Api-Key' => api_key})
|
|
165
|
+
raise Error, "Invalid response code: #{response.code}" unless response.code == 200
|
|
166
|
+
|
|
167
|
+
File.open(file_path, 'w+') do |file|
|
|
168
|
+
file.puts response.body
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def write_to_json_file(file, hash, pretty: false)
|
|
173
|
+
data =
|
|
174
|
+
if pretty
|
|
175
|
+
JSON.pretty_generate(hash)
|
|
176
|
+
else
|
|
177
|
+
hash.to_json
|
|
178
|
+
end
|
|
179
|
+
open(file, 'w') { |f| f.puts data }
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def read_from_json_file(file, symbolize_names: false)
|
|
183
|
+
return unless File.file?(file)
|
|
184
|
+
|
|
185
|
+
JSON.parse(File.read(file), symbolize_names: symbolize_names)
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
+
require "newman_scenario/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "newman_scenario"
|
|
7
|
+
spec.version = NewmanScenario::VERSION
|
|
8
|
+
spec.authors = ["Hugues Bernet-Rollande"]
|
|
9
|
+
spec.email = ["hugues@xdev.fr"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "Allow to run re-usable collection of requests using newman"
|
|
12
|
+
spec.description = <<~EOF
|
|
13
|
+
Postman doesn't support re-using the same requests in multiple scenario.
|
|
14
|
+
Duplicating request will make it hard to maintain them.
|
|
15
|
+
|
|
16
|
+
Newman allow to run a request or requests within a folder, but due to dup
|
|
17
|
+
requests, maintenance, makes it hard to build re-usable "scenario"
|
|
18
|
+
|
|
19
|
+
NewmanScenario try to fill this gap.
|
|
20
|
+
EOF
|
|
21
|
+
spec.homepage = "https://github.com/huguesbr/newman_scenario"
|
|
22
|
+
spec.license = "MIT"
|
|
23
|
+
|
|
24
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
25
|
+
spec.metadata["source_code_uri"] = "https://github.com/huguesbr/newman_scenario"
|
|
26
|
+
spec.metadata["changelog_uri"] = "https://github.com/huguesbr/newman_scenario/README.md"
|
|
27
|
+
|
|
28
|
+
# Specify which files should be added to the gem when it is released.
|
|
29
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
30
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
31
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
32
|
+
end
|
|
33
|
+
spec.bindir = "bin"
|
|
34
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
35
|
+
spec.require_paths = ["lib"]
|
|
36
|
+
spec.executables = ["newman_scenario"]
|
|
37
|
+
|
|
38
|
+
spec.add_dependency 'tty-prompt', '0.19.0'
|
|
39
|
+
spec.add_dependency 'httparty', '0.16.2'
|
|
40
|
+
spec.add_dependency 'thor', '1.0.1'
|
|
41
|
+
spec.add_dependency 'dotenv', '2.7.5'
|
|
42
|
+
|
|
43
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
|
44
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
45
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
46
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: newman_scenario
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Hugues Bernet-Rollande
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2020-04-19 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: tty-prompt
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - '='
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.19.0
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - '='
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 0.19.0
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: httparty
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - '='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 0.16.2
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - '='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 0.16.2
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: thor
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - '='
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 1.0.1
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - '='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 1.0.1
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: dotenv
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - '='
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 2.7.5
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - '='
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 2.7.5
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: bundler
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '2.0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '2.0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rake
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '10.0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '10.0'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: rspec
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '3.0'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '3.0'
|
|
111
|
+
description: |
|
|
112
|
+
Postman doesn't support re-using the same requests in multiple scenario.
|
|
113
|
+
Duplicating request will make it hard to maintain them.
|
|
114
|
+
|
|
115
|
+
Newman allow to run a request or requests within a folder, but due to dup
|
|
116
|
+
requests, maintenance, makes it hard to build re-usable "scenario"
|
|
117
|
+
|
|
118
|
+
NewmanScenario try to fill this gap.
|
|
119
|
+
email:
|
|
120
|
+
- hugues@xdev.fr
|
|
121
|
+
executables:
|
|
122
|
+
- newman_scenario
|
|
123
|
+
extensions: []
|
|
124
|
+
extra_rdoc_files: []
|
|
125
|
+
files:
|
|
126
|
+
- ".gitignore"
|
|
127
|
+
- ".rspec"
|
|
128
|
+
- ".travis.yml"
|
|
129
|
+
- CODE_OF_CONDUCT.md
|
|
130
|
+
- Gemfile
|
|
131
|
+
- Gemfile.lock
|
|
132
|
+
- LICENSE.txt
|
|
133
|
+
- README.md
|
|
134
|
+
- Rakefile
|
|
135
|
+
- bin/console
|
|
136
|
+
- bin/newman_scenario
|
|
137
|
+
- bin/rspec
|
|
138
|
+
- bin/setup
|
|
139
|
+
- lib/newman_scenario.rb
|
|
140
|
+
- lib/newman_scenario/cli.rb
|
|
141
|
+
- lib/newman_scenario/scenario.rb
|
|
142
|
+
- lib/newman_scenario/version.rb
|
|
143
|
+
- newman_scenario.gemspec
|
|
144
|
+
homepage: https://github.com/huguesbr/newman_scenario
|
|
145
|
+
licenses:
|
|
146
|
+
- MIT
|
|
147
|
+
metadata:
|
|
148
|
+
homepage_uri: https://github.com/huguesbr/newman_scenario
|
|
149
|
+
source_code_uri: https://github.com/huguesbr/newman_scenario
|
|
150
|
+
changelog_uri: https://github.com/huguesbr/newman_scenario/README.md
|
|
151
|
+
post_install_message:
|
|
152
|
+
rdoc_options: []
|
|
153
|
+
require_paths:
|
|
154
|
+
- lib
|
|
155
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
156
|
+
requirements:
|
|
157
|
+
- - ">="
|
|
158
|
+
- !ruby/object:Gem::Version
|
|
159
|
+
version: '0'
|
|
160
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
|
+
requirements:
|
|
162
|
+
- - ">="
|
|
163
|
+
- !ruby/object:Gem::Version
|
|
164
|
+
version: '0'
|
|
165
|
+
requirements: []
|
|
166
|
+
rubyforge_project:
|
|
167
|
+
rubygems_version: 2.7.7
|
|
168
|
+
signing_key:
|
|
169
|
+
specification_version: 4
|
|
170
|
+
summary: Allow to run re-usable collection of requests using newman
|
|
171
|
+
test_files: []
|