Last active
July 9, 2018 01:41
-
-
Save p4tin/7e0653aca3049b874d150b0e25387681 to your computer and use it in GitHub Desktop.
Simple dependancy Injection example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"testing" | |
) | |
var ScreenPrint = fmt.Printf | |
func Greet(name string) { | |
ScreenPrint("Hello, %s", name) | |
} | |
//func main() { | |
// Greet("Playground") | |
//} | |
func TestGreet(t *testing.T) { | |
var result string | |
ScreenPrint = func(format string, a ...interface{}) (n int, err error) { | |
result = fmt.Sprintf(format, a...) | |
n = len(result) | |
err = nil | |
return | |
} | |
expected := "Hello, Tester" | |
Greet("Tester") | |
if expected != result { | |
t.Errorf("got '%s' want '%s'", result, expected) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment