Protoc plugin to generate contract tests for gRPC in Go

Deal - Go

test codecov Go Report Card

Introduction

WE DO NOT SUPPORT THE SERVER SIDE YET

This plugin allows us to write Consumer-Driver Contracts tests!

Usage example

Proto service

First you need a proto service and add an option to it using our plugin providing the contract path:

syntax = "proto3";

import "google/protobuf/struct.proto";
import "deal/v1/contract/annotations.proto";

option go_package = "YOUR_PACKAGE_HERE/example";

message RequestMessage {
  string requestField = 1;
}

message ResponseMessage {
  int64 responseField = 1;
}

service MyService {
  rpc MyMethod(RequestMessage) returns (ResponseMessage);

  option(deal.v1.contract.deal_contract) = {
    contract_file: "contract.json"
  };
}

Contract file

After that you need to write the contract that should be respected, the contract is written as a JSON file. You can set both, Success and Failures cases:

{
  "name": "Some Name Here",
  "services": {
    "MyService": {
      "MyMethod": {
        "successCases": [
          {
            "description": "Should do something",
            "request": {
              "requestField": "VALUE"
            },
            "response": {
              "responseField": "RETURN_VALUE"
            }
          }
        ],
        "failureCases": [
          {
            "description": "Some description here",
            "request": {
              "requestField": "ANOTHER_VALUE"
            },
            "error": {
              "errorCode": "NotFound",
              "message": "ANOTHER_VALUE NotFound"
            }
          }
        ]
      }
    }
  }
}

Generating code

If you're using buf just add the following entry and execute buf generate:

version: v1beta1
plugins:
  - name: go-deal
    out: protogen
    opt: paths=source_relative

Disclaimer: You must be using go-grpc in order to make the things work

To use the generated client you can just import it from the generated module:

import "YOUR_PACKAGE_HERE/example"

func main() {
	  contractClient := example.MyServiceContractClient{}

	  // TODO: Add the rest of the example here
}
Comments
  • Support `protoreflect.Map` field type

    Support `protoreflect.Map` field type

    We need to support the protoreflect.Map in our processor field function that formats the message to its string representation!

    • [ ] Make the function works correctly withprotoreflect.Map
    • [ ] Write tests to stress as many possibilities as possible
  • Validate `Enum` values

    Validate `Enum` values

    Now we're not validation the possible Enum values, so if there's a proto file like this:

    syntax = "proto3";
    
    message RequestMessage {}
    
    message ResponseMessage {
      enum MyTest {
        ONE = 0;
        TWO = 1;
      }
    
      int64 responseField = 1;
      MyTest myTest = 2;
    }
    
    service MyService {
      rpc MyMethod(RequestMessage) returns (ResponseMessage);
    }
    

    And this contract file:

    {
      "name": "Some Name Here",
      "services": {
        "MyService": {
          "MyMethod": {
            "successCases": [
              {
                "description": "Should do something",
                "request": {
                  "requestField": "VALUE"
                },
                "response": {
                  "responseField": 42,
                  "myTest": 4
                }
              }
            ]
          }
        }
      }
    }
    

    Everything will work but we don't have four Enum options, just two (ONE, TWO) and something like this code below will be generate and probably can lead some errros:

    return &ResponseMessage{MyTest: 4, ResponseField: 42}
    
    • [ ] Validates possible Enum values
    • [ ] It'll be great to allow the user pass ONE instead of 0
  • Support `protoreflect.EnumNumber` field type

    Support `protoreflect.EnumNumber` field type

    We need to support the protoreflect.EnumNumber in our processor field function that formats the message to its string representation!

    • [ ] Make the function works correctly withprotoreflect.EnumNumber
    • [ ] Write tests to stress as many possibilities as possible
  • Support `protoreflect.List` field type

    Support `protoreflect.List` field type

    We need to support the protoreflect.List in our processor field function that formats the message to its string representation!

    • [ ] Make the function works correctly withprotoreflect.List
    • [ ] Write tests to stress as many possibilities as possible
  • Support `protoreflect.Message` field type

    Support `protoreflect.Message` field type

    We need to support the protoreflect.Message in our processor field function that formats the message to its string representation!

    • [ ] Make the function works correctly withprotoreflect.Message
    • [ ] Write tests to stress as many possibilities as possible
  • Update `README.md` with examples of how to use `deal`

    Update `README.md` with examples of how to use `deal`

    We need to put some usage examples of deal:

    • [ ] Normal client
    • [ ] Stub client
    • [ ] Server test

    As inspiration you can see our example project faunists/deal-go-example

Related tags
Protoc plugin used to generate go-kit grpc code

protoc-gen-gokit-endpoint protoc plugin used to generate go-kit grpc code 安装 go install github.com/wwbweibo/protoc-gen-gokit-endpoint/cmd/protoc-gen-g

Sep 29, 2022
Protoc plugin used to generate go-kit grpc code

protoc-gen-gokit-endpoint protoc plugin used to generate go-kit grpc code 安装 go

Sep 29, 2022
Protoc-gen-apidocs: A simple and customizable protoc generator that translates

protoc-gen-apidocs protoc-gen-apidocs is a very simple and customizable protoc g

Sep 12, 2022
A plugin of protoc that for using a service of Protocol Buffers as http.Handler definition

protoc-gen-gohttp protoc-gen-gohttp is a plugin of protoc that for using a service of Protocol Buffers as http.Handler definition. The generated inter

Dec 9, 2021
The `protoc` compiler plugin which dumps the generation request details

Progotgen DUMP The protoc compiler plugin which dumps the generation request details in "google.golang.org/protobuf/compiler/protogen format to stderr

Jan 23, 2022
A Twirp RPC OpenAPI generator implemented as `protoc` plugin

twirp-openapi-gen A Twirp RPC OpenAPI generator implemented as protoc plugin Currently supports only OpenAPI 2.0 Usage Installing the generator for pr

May 26, 2022
A protoc-gen-go wrapper including an RPC stub generator

// Copyright 2013 Google. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE fi

Nov 17, 2022
protobuf ではなく JSON でやり取りするファイルを出力する protoc プラグイン

protoc-gen-jsonif proto ファイルから、JSON フォーマットでやりとりする型定義ファイルを出力する protoc プラグインです。 proto ファイルで言語を越えて型定義が出来るのはとても良い しかし protobuf ライブラリを入れるのが面倒 今のプロジェクトには既に

Feb 28, 2022
🎉 An awesome version control tool for protoc and its related plugins.
🎉 An awesome version control tool for protoc and its related plugins.

❤️ PowerProto is actively maintained! Any questions in use can be directly raised issue, I will respond to you as fast as possible. If you think the p

Dec 29, 2022
pb: a tool for managing protoc builds and dependencies

pb pb is a Protocol Buffers Build tool that manages dependencies and build confi

Nov 20, 2022
A suite of gRPC debugging tools. Like Fiddler/Charles but for gRPC.

grpc-tools A suite of tools for gRPC debugging and development. Like Fiddler/Charles but for gRPC! The main tool is grpc-dump which transparently inte

Dec 22, 2022
grpc-http1: A gRPC via HTTP/1 Enabling Library for Go

grpc-http1: A gRPC via HTTP/1 Enabling Library for Go This library enables using all the functionality of a gRPC server even if it is exposed behind a

Dec 17, 2022
Server and client implementation of the grpc go libraries to perform unary, client streaming, server streaming and full duplex RPCs from gRPC go introduction

Description This is an implementation of a gRPC client and server that provides route guidance from gRPC Basics: Go tutorial. It demonstrates how to u

Nov 24, 2021
Go based grpc - grpc gateway micro service example

go-grpc-gateway-server This repository provides an example for go based microservice. Go micro services developed based on gRPC protobuf's and also us

Dec 8, 2021
Simple grpc web and grpc transcoding with Envoy
Simple grpc web and grpc transcoding with Envoy

gRPC Web and gRPC Transcoding with Envoy This is a simple stand-alone set of con

Dec 25, 2021
Go-grpc - This is grpc server for golang.

go-grpc This is grpc server for golang. protocのインストール brew install protoc Golang用のプラグインのインストール go install google.golang.org/protobuf/cmd/protoc-gen-go

Jan 2, 2022
GRPC - Creating a gRPC service from scratch

#Go gRPC services course Creating a gRPC service from scratch Command line colle

Jan 2, 2022
Totem - A Go library that can turn a single gRPC stream into bidirectional unary gRPC servers

Totem is a Go library that can turn a single gRPC stream into bidirectional unar

Jan 6, 2023
Grpc-gateway-map-null - gRPC Gateway test using nullable values in map

Demonstrate gRPC gateway behavior with nullable values in maps Using grpc-gatewa

Jan 6, 2022