From 55e1e90288f48716c67cdd81944c56c1e7b5023b Mon Sep 17 00:00:00 2001 From: LandonTClipp <11232769+LandonTClipp@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:35:12 -0600 Subject: [PATCH] Docs: Simplify/modernize index page --- docs/index.md | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/docs/index.md b/docs/index.md index 7eed27f1..7f54fd68 100644 --- a/docs/index.md +++ b/docs/index.md @@ -25,32 +25,25 @@ func getFromDB(db DB) string { } ``` -You can test `getFromDB` by either instantiating a testing database, or you can simply create a mock implementation of `DB` using mockery. Mockery can automatically generate a mock implementation that allows us to define assertions on how the mock was used, what to return, and other useful tidbits. We can add a `//go:generate` directive above our interface: - -```golang title="db.go" -//go:generate mockery --name DB -type DB interface { - Get(val string) string -} -``` +We can use simple configuration to generate a mock implementation for the interface: ```yaml title=".mockery.yaml" -inpackage: True # (1)! -with-expecter: True # (2)! -testonly: True # (3)! +with-expecter: True +packages: + github.com/org/repo: + interfaces: + DB: ``` -1. Generate our mocks next to the original interface -2. Create [expecter methods](features.md#expecter-structs) -3. Append `_test.go` to the filename so the mock object is not packaged - +