mocktail

command module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

README

Mocktail

Mocktail logo

Naive code generator that creates mock implementation using testify.mock.

Unlike mockery, Mocktail generates typed methods on mocks.

How to use

  • Create a file named mock_test.go inside the package that you can to create mocks.
  • Add one or multiple comments // mocktail:MyInterface inside the file mock_test.go.
package example

// mocktail:MyInterface

Notes

It requires testify >= v1.7.0

Mocktail can only generate mock of interfaces inside a module itself (not from stdlib or dependencies)

Examples

package a

import (
	"context"
	"time"
)

type Pineapple interface {
	Juice(context.Context, string, Water) Water
}

type Coconut interface {
	Open(string, int) time.Duration
}

type Water struct{}
package a

import (
	"context"
	"testing"
)

// mocktail:Pineapple
// mocktail:Coconut

func TestMock(t *testing.T) {
	var s Pineapple = newPineappleMock(t).
		OnJuice("foo", Water{}).TypedReturns(Water{}).Once().
		Parent

	s.Juice(context.Background(), "", Water{})

	var c Coconut = newCoconutMock(t).
		OnOpen("bar", 2).Once().
		Parent

	c.Open("a", 2)
}

Documentation

Overview

package main Naive code generator that creates mock implementation using `testify.mock`.

Jump to

Keyboard shortcuts

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