Skip to content

Instantly share code, notes, and snippets.

@tiborvass
Last active August 29, 2015 14:07
Show Gist options
  • Save tiborvass/fe382fcb926750a86dc5 to your computer and use it in GitHub Desktop.
Save tiborvass/fe382fcb926750a86dc5 to your computer and use it in GitHub Desktop.
Stupid github doesn't let me do slashes in filenames, so os-mock.go is os/mock.go and os-stdlib.go is os/stdlib.go.
// All you need to do is: `go test -tags mock .` to have the mocked version.
package main
import (
"fmt"
"testing"
"github.com/tiborvass/foo/os"
)
func TestFoo(t *testing.T) {
fmt.Println(os.Getenv("SHELL"))
}
// +build mock
package os
func Getenv(key string) string {
return key
}
// +build !mock
package os
import "os"
func Getenv(key string) string {
return os.Getenv(key)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment