{"id":13413926,"url":"https://github.com/GuilhermeCaruso/mooncake","last_synced_at":"2025-03-14T20:30:48.320Z","repository":{"id":59045148,"uuid":"526027204","full_name":"GuilhermeCaruso/mooncake","owner":"GuilhermeCaruso","description":":moon_cake: A simple way to generate mocks for multiple purposes","archived":false,"fork":false,"pushed_at":"2022-09-18T06:44:04.000Z","size":54,"stargazers_count":18,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-07-31T20:53:10.321Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GuilhermeCaruso.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-18T02:33:45.000Z","updated_at":"2024-06-29T07:42:04.000Z","dependencies_parsed_at":"2023-01-18T13:15:49.100Z","dependency_job_id":null,"html_url":"https://github.com/GuilhermeCaruso/mooncake","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GuilhermeCaruso%2Fmooncake","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GuilhermeCaruso%2Fmooncake/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GuilhermeCaruso%2Fmooncake/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GuilhermeCaruso%2Fmooncake/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GuilhermeCaruso","download_url":"https://codeload.github.com/GuilhermeCaruso/mooncake/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243642003,"owners_count":20323948,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T20:01:52.870Z","updated_at":"2025-03-14T20:30:47.337Z","avatar_url":"https://github.com/GuilhermeCaruso.png","language":"Go","funding_links":[],"categories":["测试","Testing","Template Engines"],"sub_categories":["HTTP客户端","Mock","HTTP Clients"],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"#\"\u003e\n    \u003cimg src=\"assets/mooncake_without_name_logo.svg\" width=\"150px\" height=\"150px\" /\u003e\n  \u003c/a\u003e\n\n  \u003ch1\u003eMooncake\u003c/h1\u003e\n  \u003cp\u003eA simple way to generate mocks for multiple purposes\u003c/p\u003e\n\n\u003c/div\u003e\n\n[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)\n[![Go Report Card](https://goreportcard.com/badge/github.com/GuilhermeCaruso/mooncake)](https://goreportcard.com/report/github.com/GuilhermeCaruso/mooncake) [![Build Status](https://app.travis-ci.com/GuilhermeCaruso/mooncake.svg?branch=main)](https://app.travis-ci.com/GuilhermeCaruso/mooncake) [![codecov](https://codecov.io/gh/GuilhermeCaruso/mooncake/branch/main/graph/badge.svg?token=MctCNBxckn)](https://codecov.io/gh/GuilhermeCaruso/mooncake) ![GitHub](https://img.shields.io/badge/golang%20-\u003e=1.18-blue.svg) [![GoDoc](https://godoc.org/github.com/GuilhermeCaruso/mooncake?status.svg)](https://godoc.org/github.com/GuilhermeCaruso/mooncake) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) \n\n**Table of Contents**\n\n- [What is Mooncake](#what-is-mooncake)\n- [Development Status](#development-status)\n- [Getting Started](#getting-start)\n  - [Installation](#installation)\n  - [Mooncake Configuration File](#mooncake-configuration-file)\n  - [How to generate](#how-to-generate)\n  - [How to use](#how-to-use)\n- [License](#license)\n\n\n## What is Mooncake\n\nMooncake is a simple way to generate mocks for multiple purposes. \n\nIt was designed to be uncomplicated and simples, focused on development agility while reducing bureaucracy.\n\nCompatible with different types of interfaces such as:\n\n- Default interfaces\n\n```go\ntype Simple interface{\n  MyMethod()\n}\n```\n\n- Nested interfaces\n\n```go\ntype Nested interface{\n  Simple\n}\n```\n\n- Generic Interfaces\n\n```go\ntype Generic[T,Z any] interface{\n  MyCustomMethod(T) (T,Z)\n}\n```\n- Generic Nested Interfaces\n\n```go\ntype NestGeneric[T,Z any] interface{\n  Generic[T,Z]\n}\n```\n\n## Development Status\n\nThis project is under development. Therefore, some features may contain minor instabilities, in addition to the possibility of new features being added periodically.\n\n\n## Getting Start\n\nTo start using `mooncake` you need to follow the steps below\n\n### Installation\n\n\nTo add mooncake to your project run:\n\n```\ngo get github.com/GuilhermeCaruso/mooncake\n```\n\nTo install the mooncake generator (`moongen`) run:\n\n```sh\ngo install github.com/GuilhermeCaruso/mooncake/moongen@v0.0.1\n```\n\n### Mooncake Configuration File\n\nOnce you have decided to use mooncake in your project you will need to create a configuration file\n\nThe file must be in the yaml extension. His name doesn't matter, however we recommend it to be mooncake\n\n- Create `mooncake.yaml` file\n\nOnce created the following template must be used\n\n```yaml\nmocks:\n  package: #package\n  path: #path\n  files:\n    - #files\n  output: #output\n  prefix: #prefix\n```\n\n| Field | Definition | Example |\n|-|-|-| \n| package | package name of files created | mocks |\n| path | path for the interfaces directory | interfaces/ |\n| files | list of interface files to be mocked | - |\n| output | path to the directory of the generated files| mocks/ |\n| prefix | optional value to be added as prefix on generated files | generated |\n\n### How to generate\n\nOnce the configuration file is done, to generate the files, run:\n\n```\nmoongen --file \u003cpath_to_config_file\u003e\n```\n\n### How to use\n\nAfter you have generated the mocks, to use the resources you can go like this:\n\n```go\npackage example\n\nimport (\n  \"testing\"\n\n  \"github.com/GuilhermeCaruso/mooncake\"\n)\n\nfunc checkValue(t *testing.T, es SimpleInterface, expectedResult string) {\n  v, err := es.Get()\n  if v != expectedResult {\n    t.Errorf(\"unexpected result. expected=%v got=%v\", expectedResult, v)\n  }\n  if err != nil {\n    t.Errorf(\"unexpected error. expected=\u003cnil\u003e got=%v\", err.Error())\n  }\n}\n\nfunc TestWithMock(t *testing.T) {\n  // Prepare new Mooncake Agent\n  a := mooncake.NewAgent()\n  // Start Implementation using created agent\n  ac := NewMockSimpleInterface(a)\n  // Define the implementation and responses\n  ac.Prepare().Get().SetReturn(\"mocked_value\", nil)\n  checkValue(t, ac, \"mocked_value\")\n}\n```\n\n\n## License\n\nMIT licensed. See the LICENSE file for details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGuilhermeCaruso%2Fmooncake","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGuilhermeCaruso%2Fmooncake","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGuilhermeCaruso%2Fmooncake/lists"}