protomock-cli v0.1.0
Protomock - CLI Mocking Tool
This CLI tool can generate and publish mock data from a protobuf file definition file. Protomock is a Typescript project.
Installation
This project uses node v16.2.0.
Clone the repo, then from the protomock dir, execute:
$ npm install
Compile
To compile js files:
$ npm run build
Usage
Prerequisite
In order to leverage the Protobuf Schemas that we have defined at Procore we need to pull the procore/types
repository.
The location of this repository then needs to be updated in the .env
file (See Environment File Settings below).
Functionality
There are 3 main functions of the CLI tool:
- Generate Mock Data based on a proto file ( Generate Only )
- Publish the data to Kafka ( Generate, then Publish )
- Consume the data from Kafka for local validation ( Consumer, then Output to Console )
To Generate Mock Data
$ npm run protomock g
To Publish Generated Data to Kafka
$ npm run protomock p
To Consume Generated Data from Kafka
$ npm run protomock c
Environment File Settings
This tool requires a .env file. You can use the .env.sample file as a template. Here are the relevant properties:
KAFKA_HOST: POST location for Publishing
KAFKA_TOPIC: Kafka Topic to Publish to
KAFKA_PRODUCE_INTERVAL_MS: How often to publish in milliseconds
NON_EVENT_PROTO_PACKAGE: proto file package name
MESSAGE_NAME: proto file message name to generate
PROTO_FILE_LOCATION: Location for proto files to process
JSON_OUTFILE_PATH: Output file dir name
EXCLUDE_PROTO_FILE: File path to exclude from processing
DATA_TEMPLATE_LOCATION: File path to shape message data
Data Shaping
This tool has a mechanism built in to allow users to shape the output data. This allows for fine control over the set of values that can be produced as well as the format.
It currently leverages the MockJS library to generate and shape the data. For detailed examples on how the data can be shaped please see:
MockJS Data Template Definitions
To specify the template location, use the DATA_TEMPLATE_LOCATION environment variable.
The template is a json file that uses the property to specify a message's field name and the value to specify the MockJS data template definition.
The mock data generator first tries to match the message's field name with its corresponding template definition. If a definition is not provided in the template, the mock data will be generated based on the data type (double, float, int32, etc).
e.g.
{
"uuid":"@guid",
"email":"@email",
"company_id":"@integer(1, 100000)"
}
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/procore/mock-service. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Code of Conduct.
Releasing
Release Strategy can be found here.
Code of Conduct
Interaction with the mock-service project codebase, issue trackers and team communication is expected to follow the Code of Conduct.
1 year ago