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"
|
import "fmt"
|
||||||
|
|
||||||
func Hello(name string) string {
|
func Hello(name string) string {
|
||||||
|
if name == "" {
|
||||||
|
return "Hello world"
|
||||||
|
}
|
||||||
return fmt.Sprintf("Hello %s", name)
|
return fmt.Sprintf("Hello %s", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,9 +3,19 @@ package main
|
|||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestHello(t *testing.T) {
|
func TestHello(t *testing.T) {
|
||||||
got := Hello("Jason")
|
t.Run("Hello someone", func(t *testing.T) {
|
||||||
exp := "Hello Jason"
|
got := Hello("Jason")
|
||||||
if got != exp {
|
exp := "Hello Jason"
|
||||||
t.Errorf("got %q expected %q", got, exp)
|
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