An open API service providing package, version and dependency metadata of many open source software ecosystems and registries.

Top 2.3% on proxy.golang.org
Top 0.5% dependent packages on proxy.golang.org
Top 0.2% dependent repos on proxy.golang.org
Top 5.9% forks on proxy.golang.org
Top 1.5% docker downloads on proxy.golang.org

proxy.golang.org : 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

Registry - Source - Documentation - JSON
purl: pkg:golang/github.com/prashantv/gostub
License: MIT
Latest release: over 3 years ago
First release: over 6 years ago
Namespace: github.com/prashantv
Dependent packages: 93
Dependent repositories: 1,804
Stars: 270 on GitHub
Forks: 13 on GitHub
Docker dependents: 9
Docker downloads: 5,019
See more repository details: repos.ecosyste.ms
Last synced: 4 days ago

    Loading...
    Readme
    Loading...