Skip to content

Instantly share code, notes, and snippets.

@webdev
Forked from ClayShentrup/stub.go
Created November 4, 2013 23:47
Show Gist options
  • Save webdev/7311417 to your computer and use it in GitHub Desktop.
Save webdev/7311417 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"reflect"
"time"
)
func main() {
stubPrototype := func(in []reflect.Value) []reflect.Value {
return []reflect.Value{reflect.ValueOf(time.Now())}
}
makeStub := func(stubbed interface{}) interface{} {
return reflect.MakeFunc(reflect.TypeOf(stubbed), stubPrototype).Interface()
}
timeStub := makeStub(time.Now).(func() time.Time)
fmt.Println(timeStub())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment