ProductPromotion
Logo

Go.Lang

made by https://0x3d.site

GitHub - GuilhermeCaruso/mooncake: :moon_cake: A simple way to generate mocks for multiple purposes
:moon_cake: A simple way to generate mocks for multiple purposes - GuilhermeCaruso/mooncake
Visit Site

GitHub - GuilhermeCaruso/mooncake: :moon_cake: A simple way to generate mocks for multiple purposes

GitHub - GuilhermeCaruso/mooncake: :moon_cake: A simple way to generate mocks for multiple purposes

Mentioned in Awesome Go Go Report Card Build Status codecov GitHub GoDoc License: MIT

Table of Contents

What is Mooncake

Mooncake is a simple way to generate mocks for multiple purposes.

It was designed to be uncomplicated and simples, focused on development agility while reducing bureaucracy.

Compatible with different types of interfaces such as:

  • Default interfaces
type Simple interface{
  MyMethod()
}
  • Nested interfaces
type Nested interface{
  Simple
}
  • Generic Interfaces
type Generic[T,Z any] interface{
  MyCustomMethod(T) (T,Z)
}
  • Generic Nested Interfaces
type NestGeneric[T,Z any] interface{
  Generic[T,Z]
}

Development Status

This project is under development. Therefore, some features may contain minor instabilities, in addition to the possibility of new features being added periodically.

Getting Start

To start using mooncake you need to follow the steps below

Installation

To add mooncake to your project run:

go get github.com/GuilhermeCaruso/mooncake

To install the mooncake generator (moongen) run:

go install github.com/GuilhermeCaruso/mooncake/[email protected]

Mooncake Configuration File

Once you have decided to use mooncake in your project you will need to create a configuration file

The file must be in the yaml extension. His name doesn't matter, however we recommend it to be mooncake

  • Create mooncake.yaml file

Once created the following template must be used

mocks:
  package: #package
  path: #path
  files:
    - #files
  output: #output
  prefix: #prefix
Field Definition Example
package package name of files created mocks
path path for the interfaces directory interfaces/
files list of interface files to be mocked -
output path to the directory of the generated files mocks/
prefix optional value to be added as prefix on generated files generated

How to generate

Once the configuration file is done, to generate the files, run:

moongen --file <path_to_config_file>

How to use

After you have generated the mocks, to use the resources you can go like this:

package example

import (
  "testing"

  "github.com/GuilhermeCaruso/mooncake"
)

func checkValue(t *testing.T, es SimpleInterface, expectedResult string) {
  v, err := es.Get()
  if v != expectedResult {
    t.Errorf("unexpected result. expected=%v got=%v", expectedResult, v)
  }
  if err != nil {
    t.Errorf("unexpected error. expected=<nil> got=%v", err.Error())
  }
}

func TestWithMock(t *testing.T) {
  // Prepare new Mooncake Agent
  a := mooncake.NewAgent()
  // Start Implementation using created agent
  ac := NewMockSimpleInterface(a)
  // Define the implementation and responses
  ac.Prepare().Get().SetReturn("mocked_value", nil)
  checkValue(t, ac, "mocked_value")
}

License

MIT licensed. See the LICENSE file for details.

Articles
to learn more about the golang concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Queries
or most google FAQ's about GoLang.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory