go-by-test/helloworld/hello_test.go

32 lines
635 B
Go
Raw Normal View History

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