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)
| 80 | // so we are not setting any expectations on the dataCollectorMock. It |
| 81 | // will still generate an access log entry though. |
| 82 | func 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 | |
| 107 | func safeClose(t *testing.T, o io.Closer) { |
| 108 | if err := o.Close(); err != nil { |
nothing calls this directly
no test coverage detected