19 lines
423 B
Go
19 lines
423 B
Go
package hello
|
|
|
|
import (
|
|
"testing"
|
|
"net/http/httptest"
|
|
)
|
|
|
|
func TestHelloHandler(t *testing.T) {
|
|
w := httptest.NewRecorder()
|
|
req := httptest.NewRequest("GET", "/hello", nil)
|
|
HelloHandler(w, req)
|
|
expected := "Hello, World!"
|
|
if w.Body.String() != expected {
|
|
t.Errorf("Expected %q but got %q", expected, w.Body.String())
|
|
}
|
|
|
|
// Force a failure for demonstration
|
|
t.Errorf("Forced failure for demonstration purposes")
|
|
} |