29 lines
555 B
Go
29 lines
555 B
Go
package greet
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
func TestService_Greet(t *testing.T) {
|
|
service := NewService()
|
|
tests := []struct {
|
|
name string
|
|
expected string
|
|
}{
|
|
{"", "Hello world!"},
|
|
{"John", "Hello John!"},
|
|
{"Alice", "Hello Alice!"},
|
|
{" ", "Hello !"}, // spaces are not considered empty
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := service.Greet(context.Background(), tt.name)
|
|
if result != tt.expected {
|
|
t.Errorf("Greet(%q) = %q, want %q", tt.name, result, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|