Mock-the-fck - Mock exercise for human

Overview

Mock the fck

Originally, Mockery-example

Example case for mockery issue #128 filed with the golang tool "mockery".

Sample output:

$ go run main.go
common prefix: {
  Prefix: "2017-01-01"
}
content: {
  Key: "foo-object"
}

How to generate S3API from vendor code ?

use go mod vendor to download code

warning

  • s3 is a struct, so

mockgen --build_flags=--mod=mod github.com/aws/aws-sdk-go/service/s3 S3 is wrong

1. Mockgen

S3API is interface

mockgen --build_flags=--mod=mod github.com/aws/aws-sdk-go/service/s3/s3iface S3API > mocks/second_mocks.go

2. Mockery

What if I want mockery api for mocking and generation ??

  1. add _ "github.com/aws/aws-sdk-go/service/s3/s3iface/interface.go"
  2. go mod vendor
  3. run below, but mocks/S3API.go will be overwritten !!!
mockery --dir vendor/github.com/aws/aws-sdk-go/service/s3/s3iface --name S3API

other takeaway cmds

run go mod vendor to pull code

mockgen --build_flags=--mod=mod vendor/github.com/aws/aws-sdk-go/service/s3 S3

import _ "github.com/golang/mock/mockgen/model"

Issue of method 2 under Q&A readme of mockgen

Better try method 3 !

mockgen vendor/github.com/aws/aws-sdk-go/service/s3 S3

prog.go:14:2: use of vendored package not allowed
prog.go:12:2: no required module provides package github.com/golang/mock/mockgen/model: go.mod file not found in current directory or any parent directory; see 'go help modules'
prog.go:14:2: vendor/github.com/aws/aws-sdk-go/service/s3 must be imported as github.com/aws/aws-sdk-go/service/s3
2022/01/21 17:54:17 Loading input failed: exit status 1

Buggy Test Coverage

run test with coverage. shows main.go 0% covered, but mocks folder has 33%!!!

Why on earth we calculate coverage stats on that bits !!

Futures

  1. Why gomock or mockery not generate from struct as extra feature, as in case of s3 struct.

  2. gcp sdk Has more good pratices

  3. more gcp shows fake data has been set in google style.

But, this blog points out:

Google engineer prefer hand-code fake rather reflection mock

Andrew Gerrand mentions gomock, a mocking library, and reluctantly says

[mocking libraries like gomock] are fine, 
but I find that on balance the hand-written fakes tend be easier to reason about 
and clearer to see what's going on, but I'm not an enterprise go programmer 
so maybe people do need that so I don't know, but that's my advice.
  1. uber/kraken Manually create s3 interface. But their Makefile mockgen heaps of stuff !!

  2. aws-go Lots of http code

  3. counterfeiter demo by mario Probably interesting

Owner
Mike Cat
Go, Python, Js
Mike Cat
Vault mock - Mock of Hashicorp Vault used for unit testing

vault_mock Mock of Hashicorp Vault used for unit testing Notice This is a person

Elliot Rotenstein 0 Jan 19, 2022
Sql mock driver for golang to test database interactions

Sql driver mock for Golang sqlmock is a mock library implementing sql/driver. Which has one and only purpose - to simulate any sql driver behavior in

DATA-DOG 4.4k May 14, 2022
HTTP mock for Golang: record and replay HTTP/HTTPS interactions for offline testing

govcr A Word Of Warning I'm in the process of partly rewriting govcr to offer better support for cassette mutations. This is necessary because when I

Seb C 105 May 18, 2022
Powerful mock generation tool for Go programming language

Summary Minimock generates mocks out of Go interface declarations. The main features of minimock are: It generates statically typed mocks and helpers.

Juno Inc. 452 May 1, 2022
Mock object for Go http.ResponseWriter

mockhttp -- Go package for unit testing HTTP serving Unit testing HTTP services written in Go means you need to call their ServeHTTP receiver. For thi

Tv 21 Mar 22, 2022
ESME is a go library that allows you to mock a RESTful service by defining the configuration in json format

ESME is a go library that allows you to mock a RESTful service by defining the configuration in json format. This service can then simply be consumed by any client to get the expected response.

Sumit Tokkar 3 Mar 2, 2021
mockery - A mock code autogenerator for Golang

mockery - A mock code autogenerator for Golang

Vektra 3.5k May 15, 2022
Create your own mock server with just a JSON file!

Gmocker Run a blazing fast mock server in just seconds! ?? All you need is to make a json file that contains path and response mapping. See an example

Ananto 49 Apr 13, 2022
Create your own blazing fast mock server with just a JSON file!

Gmocker Run a blazing fast mock server in just seconds! ?? All you need is to make a json file that contains path and response mapping. See an example

Ananto 49 Apr 13, 2022
Vitaly Berg 7 Aug 10, 2021
Completely type-safe compile-time mock generator for Go

Mockc Mockc is a completely type-safe compile-time mock generator for Go. You can use it just by writing the mock generators with mockc.Implement() or

Geon Kim 29 May 23, 2021
Merge Mock - testing tool for the Ethereum Merge

MergeMock Experimental debug tooling, mocking the execution engine and consensus node for testing. work in progress Quick Start To get started, build

Diederik Loerakker 24 May 3, 2022
A basic lightweight HTTP client for Go with included mock features.

A basic lightweight HTTP client for Go with included mock features. Features Support almost all http method like G

Andres Mijares 1 May 2, 2022
📡 mock is a simple, cross-platform, cli app to simulate HTTP-based APIs.

mock ?? mock is a simple, cross-platform, cli app to simulate HTTP-based APIs. About mock Mock allows you to spin up a local http server based of a .m

Bruno Schaatsbergen 8 May 6, 2022
A mock of Go's net package for unit/integration testing

netmock: Simulate Go network connections netmock is a Go package for simulating net connections, including delays and disconnects. This is work in pro

Lucas Wolf 1 Oct 27, 2021
Mock API for REST!!!!

Mock API Server Introduction This app allows you to add urls and serve dummy json responses. It contains two handlers, the DummyHandler allows you to

null 2 Nov 17, 2021
Just Dance Unlimited mock-up server written on Golang and uses a popular Gin framework for Go.

BDCS Just Dance Unlimited mock-up server written on Golang and uses a popular Gin framework for Go. Features Security Authorization works using UbiSer

Mikhail 0 Nov 10, 2021
Simple mock program to set charging rate of a battery instance based on the national grid intensity api

Charger Simple mock program to set charging rate of a battery instance based on the national grid intensity api. Steps to get up and running I have cr

Taj 0 Nov 16, 2021
A tool that integrates SQL, HTTP,interface,Redis mock

Mockit 目标:将mock变得简单,让代码维护变得容易 分支介绍 main 主分支,覆盖了单元测试 light 轻分支,去除了单元测试,简化了依赖项,方便其他团队使用 常见Mock难点 不同中间件,mock库设计模式不一致,学习代价高,差异化明显 mock方案强依赖服务端,无法灵活解耦 单元测试

SHIHUO 14 Apr 19, 2022