From 4eddefe889358ad06c0037b8917ffb9a04368afe Mon Sep 17 00:00:00 2001 From: itpey Date: Fri, 3 May 2024 01:04:38 +0330 Subject: [PATCH] Update --- README.md | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++- app/cli.go | 4 +- 2 files changed, 124 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bebe72b..e43e200 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,122 @@ -# jettest - A command-line tool for running API tests using YAML configuration files. +[//]: # "Title: jettest" +[//]: # "Author: itpey" +[//]: # "Attendees: itpey" +[//]: # "Tags: #itpey #go #test #golang #go-lang #cli #api #http #jettest" + +

+itpey JetTest jettest +

+ +

+ JetTest +

+ +

+JetTest is a versatile command-line tool designed for effortless API testing using YAML-based configuration files. +

+ +

+ + itpey JetTest Go Reference + + + itpey JetTest license + +

+ +# Features + +- **Simple YAML Configuration**: Define API tests easily using YAML files. +- **Flexible HTTP Methods**: Supports GET, POST, and PUT requests. +- **Customizable Parameters**: Specify API host, client ID, authentication token, and request timeout. +- **Debug Mode**: Enable detailed logging for request and response information. +- **Response Validation**: Validate expected status codes, response latency, and specific response body segments. + +# Installation + +Make sure you have Go installed and configured on your system. Use go install to install JetTest: + +```bash +go install github.com/itpey/jettest@latest +``` + +Ensure that your `GOBIN` directory is in your `PATH` for the installed binary to be accessible globally. + +# Usage + +```bash +jettest --host --file [OPTIONS] +``` + +### Options + +- `--host `: Specify the API host (required). +- `--file, -f `: Path to the YAML test file (required). +- `--clientID, --cid `: Set the client ID for requests. +- `--authToken, --at `: Provide an authentication token for requests. +- `--timeout, -t `: Set the request timeout duration in seconds (default: 30). +- `--debug, -d`: Enable debug mode to print detailed request and response information. + +## Example + +Execute JetTest to run API tests against a target host using a specific YAML configuration file: + +```bash +jettest --host https://api.example.com --file file.yaml --clientID myclient --authToken mytoken --timeout 60 --debug +``` + +# YAML Test Configuration + +Define API tests in a YAML configuration file `file.yaml` with the following structure: + +```yaml +tests: + - name: Get user profile + description: Retrieve user profile information + request: + method: GET + path: /api/users/profile + params: + user_id: [12345] + with_token: true + expect: + status_code: 200 + max_latency: 5000ms + body: + - path: data.username + value: "john_doe" + - path: data.email + value: "john.doe@example.com" +``` + +### Explanation + +- `name`: Name of the API test. +- `request`: Details of the API request. +- `method`: HTTP method (GET, POST, PUT). +- `path`: Endpoint path. +- `params`: Query parameters. +- `headers`: Request headers. +- `with_client_id`: Include client ID in headers (true/false). +- `with_token`: Include authentication token in headers (true/false). +- `body`: Request body (if applicable). +- `expect`: Expected response conditions. +- `status_code`: Expected HTTP status code. +- `max_latency`: Maximum acceptable response latency. +- `body`: List of expected response body conditions. + +For more examples and detailed usage, refer to the [examples](https://github.com/itpey/jettest/tree/main/examples) examples provided in the repository. + +# Feedback and Contributions + +If you encounter any issues or have suggestions for improvement, please [open an issue](https://github.com/itpey/jettest/issues) on GitHub. + +We welcome contributions! Fork the repository, make your changes, and submit a pull request. + +# License + +JetTest is open-source software released under the Apache License, Version 2.0. You can find a copy of the license in the [LICENSE](https://github.com/itpey/jettest/blob/main/LICENSE) file. + +# Author + +JetTest was created by [itpey](https://github.com/itpey) diff --git a/app/cli.go b/app/cli.go index ea0c3f3..e755b53 100644 --- a/app/cli.go +++ b/app/cli.go @@ -73,7 +73,7 @@ type request struct { Path string `yaml:"path"` Params url.Values `yaml:"params"` Headers http.Header `yaml:"headers"` - WithClientID bool `yaml:"with_clientID"` + WithClientID bool `yaml:"with_client_id"` WithAuthToken bool `yaml:"with_token"` Body string `yaml:"body"` } @@ -86,7 +86,7 @@ type input struct { // Expect contains the expectations of the API response or behavior type expect struct { StatusCode int `yaml:"status_code"` - MaxLatency time.Duration `yaml:"max_latnecy"` + MaxLatency time.Duration `yaml:"max_latency"` Body []body `yaml:"body"` }