funcy

package module
v0.0.0-...-b94814c Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2018 License: MIT Imports: 18 Imported by: 0

README

funcy-mock

Go Report Card

funcy-mock generates mock file from interface go file

Synopsis

You can try following:

  • git clone git@github.com:Code-Hex/funcy-mock.git && cd funcy-mock/tmp
  • funcygen demo.go

If you have some question, You run funcygen -h or report to issue.

Description

THIS TOOL IS BETA QUALITY.

funcygen just by specifying the Go file described the interface, we will generate a go file containing the mock code.

Installation

go get github.com/cmd/funcygen

Generated file

from demo.go to demo_mock_for_test.go

package main

import (
	"context"
	"github.com/Code-Hex/funcy-mock/tmp/internal/auth"
	"github.com/Code-Hex/funcy-mock/tmp/internal/user"
)

type UserServiceMock struct {
	auth func(context.Context) (*auth.Token, error)
	get  func() (*user.Response, error)
}

func NewUserServiceMock() *UserServiceMock {
	return &UserServiceMock{
		auth: func(context.Context) (*auth.Token, error) { return nil, nil },
		get:  func() (*user.Response, error) { return nil, nil },
	}
}

func (u *UserServiceMock) Auth(ctx context.Context) (*auth.Token, error) {
	return u.auth()
}

func (u *UserServiceMock) SetAuth(f func(context.Context) (*auth.Token, error)) {
	if f == nil {
		panic("You should specify the mock function")
	}
	u.auth = f
}

func (u *UserServiceMock) Get() (*user.Response, error) {
	return u.get()
}

func (u *UserServiceMock) SetGet(f func() (*user.Response, error)) {
	if f == nil {
		panic("You should specify the mock function")
	}
	u.get = f
}

type AuthServiceMock struct {
	auth func(context.Context) (*auth.Token, error)
}

func NewAuthServiceMock() *AuthServiceMock {
	return &AuthServiceMock{
		auth: func(context.Context) (*auth.Token, error) { return nil, nil },
	}
}

func (a *AuthServiceMock) Auth(ctx context.Context) (*auth.Token, error) {
	return a.auth()
}

func (a *AuthServiceMock) SetAuth(f func(context.Context) (*auth.Token, error)) {
	if f == nil {
		panic("You should specify the mock function")
	}
	a.auth = f
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run() int

func UnwrapErrors

func UnwrapErrors(err error) (int, error)

UnwrapErrors get important message from wrapped error message

Types

type Interface

type Interface struct {
	Name   string
	Param  *Param
	Return *Return
}

func (*Interface) PrivateName

func (i *Interface) PrivateName() string

type Options

type Options struct {
	Help    bool   `short:"h" long:"help" description:"show this message"`
	Package string `short:"p" long:"pkg" description:"specify the package name"`
	Dest    string `short:"d" long:"dest" description:"specify the output destination"`
}

type Param

type Param struct {
	TypeOnly string
	NameOnly string
	Field    string
}

type Return

type Return struct {
	Type  string
	Value string
}

Directories

Path Synopsis
cmd
tmp

Jump to

Keyboard shortcuts

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