MCPcopy
hub / github.com/IBM/sarama / TestWrongPath

Function TestWrongPath

examples/http_server/http_server_test.go:82–105  ·  view source on GitHub ↗

We don't expect any data collector calls because the path is wrong, so we are not setting any expectations on the dataCollectorMock. It will still generate an access log entry though.

(t *testing.T)

Source from the content-addressed store, hash-verified

80// so we are not setting any expectations on the dataCollectorMock. It
81// will still generate an access log entry though.
82func TestWrongPath(t *testing.T) {
83 dataCollectorMock := mocks.NewSyncProducer(t, nil)
84
85 accessLogProducerMock := mocks.NewAsyncProducer(t, nil)
86 accessLogProducerMock.ExpectInputAndSucceed()
87
88 s := &Server{
89 DataCollector: dataCollectorMock,
90 AccessLogProducer: accessLogProducerMock,
91 }
92 defer safeClose(t, s)
93
94 req, err := http.NewRequest("GET", "http://example.com/wrong?data", nil)
95 if err != nil {
96 t.Fatal(err)
97 }
98 res := httptest.NewRecorder()
99
100 s.Handler().ServeHTTP(res, req)
101
102 if res.Code != 404 {
103 t.Errorf("Expected HTTP status 404, found %d", res.Code)
104 }
105}
106
107func safeClose(t *testing.T, o io.Closer) {
108 if err := o.Close(); err != nil {

Callers

nothing calls this directly

Calls 7

ExpectInputAndSucceedMethod · 0.95
HandlerMethod · 0.95
NewSyncProducerFunction · 0.92
NewAsyncProducerFunction · 0.92
FatalMethod · 0.80
safeCloseFunction · 0.70
ErrorfMethod · 0.65

Tested by

no test coverage detected