Created
November 28, 2014 16:28
-
-
Save ae6rt/6959dd50e3a98ec0a1c7 to your computer and use it in GitHub Desktop.
Restore default implementations of code in Go unit tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If you replace a default function in a package for unit testing purposes, make sure you | |
restore it so the next test does not mistakenly inherit the reassignment: | |
func TestEndpointNoScopes(t *testing.T) { | |
saveAuth := auth | |
defer func() { | |
auth = saveAuth | |
}() | |
auth = func(*http.Request, []string) (bool, error) { | |
return false, fmt.Errorf("some error") | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment