grpc

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 22 Imported by: 2

README

Venom - Executor Grpc

Step for execute GRPC Request

Based on grpcurl, see grpcurl for more information. This executor relies on the gRPC server reflection, which should be enabled on the server as described here. gRPC server reflection is not enabled by default and not implemented for every gRPC library, make sure your library of choice supports reflection before implementing tests using this executor. gRPC server reflection also does not properly work with gogo/protobuf: grpc/grpc-go#1873

Tests

Results of test are parsed as json and saved in systemoutjson. Status codes correspond to the official status codes of gRPC. You can find what individual return codes mean here.

Input

In your yaml file, you can use:

  - url mandatory
  - service mandatory: service to call
  - method mandatory: list, describe, or method of the endpoint
  - data optional: data to marshal to json and send as a request
  - headers optional: data to send as additional headers
  - connect_timeout optional: The maximum time, in seconds, to wait for connection to be established. Defaults to 10 seconds
  - default_fields optional: whether json formatter should emit default fields
  - include_text_separator optional: when protobuf string formatter is invoked to format multiple messages, all messages after the first one will be prefixed with character (0x1E)
  - tls_client_cert optional: a chain of certificates to identify the caller, first certificate in the chain is considered as the leaf, followed by intermediates. Setting it enable mutual TLS authentication. Set the PEM content or the path to the PEM file.
  - tls_client_key optional: private key corresponding to the certificate. Set the PEM content or the path to the PEM file.
  - tls_root_ca optional: defines additional root CAs to perform the call. can contains multiple CAs concatenated together. Set the PEM content or the path to the PEM file.
  - ignore_verify_ssl optional: set to true if you use a self-signed SSL on remote for example

Example:


name: Title of TestSuite
testcases:

- name: request GRPC
  steps:
  - type: grpc
    url: serverUrlWithoutHttp:8090
    data:
      foo: bar
    service: coolService.api
    method: GetAllFoos
    assertions:
    - result.code ShouldEqual 0
    - result.systemoutjson.foo ShouldEqual bar

Example TLS:


name: Title of TestSuite
testcases:

- name: request GRPC
  steps:
  - type: grpc
    url: serverUrlWithoutHttp:8090
    tls_root_ca: |-
      -----BEGIN CERTIFICATE-----
      ...
      -----END CERTIFICATE-----
    ignore_verify_ssl: true # true for self signed certificates
    data:
      foo: bar
    service: coolService.api
    method: GetAllFoos
    assertions:
    - result.code ShouldEqual 0
    - result.systemoutjson.foo ShouldEqual bar

Example mutual TLS:


name: Title of TestSuite
testcases:

- name: request GRPC
  steps:
  - type: grpc
    url: serverUrlWithoutHttp:8090
    tls_root_ca: |-
      -----BEGIN CERTIFICATE-----
      ...
      -----END CERTIFICATE-----
    tls_client_cert: |-
      -----BEGIN CERTIFICATE-----
      ...
      -----END CERTIFICATE-----
    tls_client_key: |-
      -----BEGIN PRIVATE KEY-----
      ...
      -----END PRIVATE KEY-----
    ignore_verify_ssl: true # true for self signed certificates
    data:
      foo: bar
    service: coolService.api
    method: GetAllFoos
    assertions:
    - result.code ShouldEqual 0
    - result.systemoutjson.foo ShouldEqual bar

Output

executor
systemout
systemerr
err
code
timeseconds
  • result.timeseconds: execution duration
  • result.executor.executor.script: script executed
  • result.err: if exists, this field contains error
  • result.systemout: Standard Output of executed script
  • result.systemerr: Error Output of executed script
  • result.code: Exit Code

Documentation

Index

Constants

View Source
const Name = "grpc"

Name for test exec

Variables

This section is empty.

Functions

func New

func New() venom.Executor

New returns a new Test Exec

Types

type Executor

type Executor struct {
	URL                  string                 `json:"url" yaml:"url"`
	Service              string                 `json:"service" yaml:"service"`
	Method               string                 `json:"method" yaml:"method"`
	JSONDefaultFields    bool                   `json:"default_fields" yaml:"default_fields"`
	IncludeTextSeparator bool                   `json:"include_text_separator" yaml:"include_text_separator"`
	Data                 map[string]interface{} `json:"data" yaml:"data"`
	Headers              map[string]string      `json:"headers" yaml:"headers"`
	ConnectTimeout       *int64                 `json:"connect_timeout" yaml:"connect_timeout"`
	TLSClientCert        string                 `json:"tls_client_cert" yaml:"tls_client_cert" mapstructure:"tls_client_cert"`
	TLSClientKey         string                 `json:"tls_client_key" yaml:"tls_client_key" mapstructure:"tls_client_key"`
	TLSRootCA            string                 `json:"tls_root_ca" yaml:"tls_root_ca" mapstructure:"tls_root_ca"`
	IgnoreVerifySSL      bool                   `json:"ignore_verify_ssl" yaml:"ignore_verify_ssl" mapstructure:"ignore_verify_ssl"`
}

Executor represents a Test Exec

func (Executor) GetDefaultAssertions

func (Executor) GetDefaultAssertions() *venom.StepAssertions

GetDefaultAssertions return default assertions for type exec

func (Executor) Run

func (Executor) Run(ctx context.Context, step venom.TestStep) (interface{}, error)

Run execute TestStep of type exec

func (Executor) ZeroValueResult

func (Executor) ZeroValueResult() interface{}

ZeroValueResult return an empty implementation of this executor result

type Result

type Result struct {
	Systemout     string      `json:"systemout,omitempty" yaml:"systemout,omitempty"`
	SystemoutJSON interface{} `json:"systemoutjson,omitempty" yaml:"systemoutjson,omitempty"`
	Systemerr     string      `json:"systemerr,omitempty" yaml:"systemerr,omitempty"`
	SystemerrJSON interface{} `json:"systemerrjson,omitempty" yaml:"systemerrjson,omitempty"`
	Err           string      `json:"err,omitempty" yaml:"err,omitempty"`
	Code          string      `json:"code,omitempty" yaml:"code,omitempty"`
	TimeSeconds   float64     `json:"timeseconds,omitempty" yaml:"timeseconds,omitempty"`
}

Result represents a step result

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL