learn-go-with-tests/hello_test.go

28 lines
537 B
Go
Raw Normal View History

2022-01-26 13:12:15 +00:00
package main
import "testing"
func TestHello(t *testing.T) {
2022-01-27 18:00:00 +00:00
assertCorrectMessage := func(t testing.TB, got string, want string) {
t.Helper()
2022-01-26 13:12:15 +00:00
2022-01-26 18:00:00 +00:00
if got != want {
t.Errorf("got %q want %q", got, want)
}
2022-01-27 18:00:00 +00:00
}
t.Run("saying hello to people", func (t *testing.T) {
got := Hello("Oliver")
want := "Hello, Oliver"
assertCorrectMessage(t, got, want)
2022-01-26 18:00:00 +00:00
})
t.Run("say 'Hello, World' when an empty string is supplied", func (t *testing.T) {
got := Hello("")
want := "Hello, World"
2022-01-27 18:00:00 +00:00
assertCorrectMessage(t, got, want)
})
2022-01-26 13:12:15 +00:00
}