// MockKrakenProvider mocks a Kraken server.
MockKrakenProvider mocks a Kraken server.
// MockKrakenProvider mocks a Kraken server .
func MockKrakenProvider() *httptest.Server {
	return httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		switch r.RequestURI {
		case krakenHealthPath:
			if r.Method != http.MethodGet {
				w.WriteHeader(http.StatusNotImplemented)
				return
			}
			w.WriteHeader(http.StatusOK)
		case krakenPreheatPath:
			if r.Method != http.MethodPost {
				w.WriteHeader(http.StatusNotImplemented)
				return
			}
			data, err := ioutil.ReadAll(r.Body)
			if err != nil {
				w.WriteHeader(http.StatusInternalServerError)
				_, _ = w.Write([]byte(err.Error()))
				return
			}
			var payload = &notification.Notification{
				Events: []notification.Event{},
			}
			if err := json.Unmarshal(data, payload); err != nil {
				w.WriteHeader(http.StatusInternalServerError)
				_, _ = w.Write([]byte(err.Error()))
				return
			}
			if len(payload.Events) > 0 {
				w.WriteHeader(http.StatusOK)
				return
			}
			w.WriteHeader(http.StatusBadRequest)
		default:
			w.WriteHeader(http.StatusNotImplemented)
		}
	}))
}
func MockKrakenProvider ( ) * httptest . Server { return httptest . NewUnstartedServer ( http . HandlerFunc ( func ( w http . ResponseWriter , r * http . Request ) { switch r . RequestURI { case krakenHealthPath : if r . Method != http . MethodGet { w . WriteHeader ( http . StatusNotImplemented ) return } w . WriteHeader ( http . StatusOK ) case krakenPreheatPath : if r . Method != http . MethodPost { w . WriteHeader ( http . StatusNotImplemented ) return } data , err := ioutil . ReadAll ( r . Body ) if err != nil { w . WriteHeader ( http . StatusInternalServerError ) _ , _ = w . Write ( [ ] byte ( err . Error ( ) ) ) return } var payload = & notification . Notification { Events : [ ] notification . Event { } , } if err := json . Unmarshal ( data , payload ) ; err != nil { w . WriteHeader ( http . StatusInternalServerError ) _ , _ = w . Write ( [ ] byte ( err . Error ( ) ) ) return } if len ( payload . Events ) > 0 { w . WriteHeader ( http . StatusOK ) return } w . WriteHeader ( http . StatusBadRequest ) default : w . WriteHeader ( http . StatusNotImplemented ) } } ) ) }
MockKrakenProvider mocks a Kraken server.
MockKrakenProvider mocks a Kraken server .