Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
243826 authored Sep 11, 2023
1 parent ca1b86c commit fe48321
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# envygo
Environment aware mocking library for golang

```golang
import env github.com/celeral/envygo
```
## motivation
So much has been made out of mocking while testing. There are elaborate framewors where a Golang coder is expected to create the interfaces and then generate code from these interfaces that can be used to verify certain behavior. Many of these frameworks are wildly accepted, probably because these framework capitalized on a certain taste the developers developed and came to expect from mocking libraries prior to advent of Golang. Yet article after article, especially when we talk about missing polymorphism in Golang, we talk about how the function of Go function should be modified by passing it a function as an argument.

Expand All @@ -24,7 +26,7 @@ func ReadConfiguration(relativePath string) Config, error {
### test
```golang
func TestReadConfigurationCaseEmptyFile(t *testing.T) {
defer Mock(Os, "ReadFile", func(name string) ([]byte, error) { return []byte{}, nil })()
defer MockField(Os, "ReadFile", func(name string) ([]byte, error) { return []byte{}, nil })()

if config, err := ReadConfiguration("this/path/does/not/exist"); err != nil {
if !config.IsEmpty() {
Expand All @@ -40,6 +42,12 @@ How is this possible, I hear some of you ask. Only "some" because others probabl

### src again
```golang
import env github.com/celeral/envygo

var Mock = env.Mock
var Unmock = env.Unmock
var MockField = env.MockField

var Os = &struct {
Create func(name string) (*os.File, error)
ReadFile func(name string) ([]byte, error)
Expand Down

0 comments on commit fe48321

Please sign in to comment.