Test if functions are called

Open
#751 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
25/100
Issue type
Documentation
Clarity
Needs clarification
Activity status
Stale
Tech stack
go
Domain
testing

Research direction

The issue provides only the AddToManager and AddToPagerFuncs example and does not name a repository file or test. Start by reviewing Testify's mocking and function-call assertion documentation, then determine whether guidance or a focused example test is needed for verifying each function call exactly once.

Written by the indexing model from the issue text.

Description

I am new to Golang and trying testify for the first time. I have following code to test.


var AddToPagerFuncs []func(int) error

func AddToManager(p pager.Pager) error {
	for _, f := range AddToPagerFuncs {
		if err := f(p); err != nil {
			return err
		}
	}
	return nil
}

To test above code I'll have a list of functions and add them to AddToPagerFuncs list. After that I'll call a function AddToManager with mock Pager. Now I want to verify that all the functions I added to list are called once. Any guidance how to do that using testify ?

Dominant language
Go
Stars
26.2k
Forks
1.9k
Avg merge
2d 4h
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stretchr/testify

All issues in stretchr/testify

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.