| 1 |
package gostub_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"os" |
| 6 |
|
| 7 |
"github.com/prashantv/gostub" |
| 8 |
) |
| 9 |
|
| 10 |
func ExampleStubFunc() { |
| 11 |
var osHostname = os.Hostname |
| 12 |
|
| 13 |
defer gostub.StubFunc(&osHostname, "fakehost", nil).Reset() |
| 14 |
host, err := osHostname() |
| 15 |
|
| 16 |
fmt.Println("Host:", host, "err:", err) |
| 17 |
// Output: |
| 18 |
// Host: fakehost err: <nil> |
| 19 |
} |
| 20 |
|
| 21 |
func ExampleStub() { |
| 22 |
var counter = 100 |
| 23 |
|
| 24 |
defer gostub.Stub(&counter, 200).Reset() |
| 25 |
fmt.Println("Counter:", counter) |
| 26 |
// Output: |
| 27 |
// Counter: 200 |
| 28 |
} |