go-by-test/helloworld/hello_test.go

32 lines
635 B
Go
Raw Permalink Normal View History

2024-09-10 09:47:40 +00:00
package helloworld
2024-09-10 09:06:51 +00:00
import "testing"
func TestHello(t *testing.T) {
2024-09-10 09:44:21 +00:00
initDefaults()
2024-09-10 09:12:42 +00:00
t.Run("Hello someone", func(t *testing.T) {
2024-09-10 09:35:30 +00:00
got := Hello("Jason", "English")
2024-09-10 09:12:42 +00:00
exp := "Hello Jason"
2024-09-10 09:20:52 +00:00
assertCorrectMsg(t, got, exp)
2024-09-10 09:12:42 +00:00
})
t.Run("Hello default", func(t *testing.T) {
2024-09-10 09:35:30 +00:00
got := Hello("", "English")
2024-09-10 09:12:42 +00:00
exp := "Hello world"
2024-09-10 09:20:52 +00:00
assertCorrectMsg(t, got, exp)
2024-09-10 09:12:42 +00:00
})
2024-09-10 09:35:30 +00:00
t.Run("Hello default", func(t *testing.T) {
got := Hello("Elodie", "Spanish")
exp := "Hola Elodie"
assertCorrectMsg(t, got, exp)
})
2024-09-10 09:06:51 +00:00
}
2024-09-10 09:20:52 +00:00
func assertCorrectMsg(t testing.TB, got, exp string) {
t.Helper()
if got != exp {
t.Errorf("got %q expected %q", got, exp)
}
}