hello default world
This commit is contained in:
parent
f13632e425
commit
cbd4cf628f
3
hello.go
3
hello.go
@ -3,6 +3,9 @@ package main
|
||||
import "fmt"
|
||||
|
||||
func Hello(name string) string {
|
||||
if name == "" {
|
||||
return "Hello world"
|
||||
}
|
||||
return fmt.Sprintf("Hello %s", name)
|
||||
}
|
||||
|
||||
|
@ -3,9 +3,19 @@ package main
|
||||
import "testing"
|
||||
|
||||
func TestHello(t *testing.T) {
|
||||
got := Hello("Jason")
|
||||
exp := "Hello Jason"
|
||||
if got != exp {
|
||||
t.Errorf("got %q expected %q", got, exp)
|
||||
}
|
||||
t.Run("Hello someone", func(t *testing.T) {
|
||||
got := Hello("Jason")
|
||||
exp := "Hello Jason"
|
||||
if got != exp {
|
||||
t.Errorf("got %q expected %q", got, exp)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Hello default", func(t *testing.T) {
|
||||
got := Hello("")
|
||||
exp := "Hello world"
|
||||
if got != exp {
|
||||
t.Errorf("got %q expected %q", got, exp)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user