An open API service providing repository metadata for many open source software ecosystems.

Package Usage: go: github.com/prashantv/gostub

Package gostub is used for stubbing variables in tests, and resetting the original value once the test has been run. This can be used to stub static variables as well as static functions. To stub a static variable, use the Stub function: gostub can also stub static functions in a test by using a variable to reference the static function, and using that local variable to call the static function: You can test this by using gostub to stub the timeNow variable: If you are stubbing a function to return a constant value like in the above test, you can use StubFunc instead: StubFunc can also be used to stub functions that return multiple values: StubEnv can be used to setup environment variables for tests, and the environment values are reset to their original values upon Reset: The Reset method should be deferred to run at the end of the test to reset all stubbed variables back to their original values. You can set up multiple stubs by calling Stub again: For simple cases where you are only setting up simple stubs, you can condense the setup and cleanup into a single line: This sets up the stubs and then defers the Reset call. You should keep the return argument from the Stub call if you need to change stubs or add more stubs during test execution: The Stub call must be passed a pointer to the variable that should be stubbed, and a value which can be assigned to the variable. Test code Test code
2 versions
Latest release: over 3 years ago
93 dependent packages

View more package details: https://packages.ecosystem.code.gouv.fr/registries/proxy.golang.org/packages/github.com/prashantv/gostub

Dependent Repos 0