Skip to content

Commit

Permalink
Rename events route (#1483)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl authored Aug 27, 2024
2 parents ad107d0 + b0cc175 commit 7354e50
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions alerts/alerts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestWebhooks(t *testing.T) {
mux := http.NewServeMux()
var events []webhooks.Event
var mu sync.Mutex
mux.HandleFunc("/events", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/event", func(w http.ResponseWriter, r *http.Request) {
var event webhooks.Event
if err := json.NewDecoder(r.Body).Decode(&event); err != nil {
t.Fatal(err)
Expand All @@ -72,7 +72,7 @@ func TestWebhooks(t *testing.T) {
// register a hook
wh := webhooks.Webhook{
Module: webhookModule,
URL: fmt.Sprintf("http://%v/events", srv.Listener.Addr().String()),
URL: fmt.Sprintf("http://%v/event", srv.Listener.Addr().String()),
}
if hookID := wh.String(); hookID != fmt.Sprintf("%v.%v.%v", wh.URL, wh.Module, "") {
t.Fatalf("wrong result for wh.String(): %v != %v", wh.String(), hookID)
Expand Down
4 changes: 2 additions & 2 deletions internal/worker/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestEventSubscriber(t *testing.T) {
}

// setup a server
mux := jape.Mux(map[string]jape.Handler{"POST /events": func(jc jape.Context) {
mux := jape.Mux(map[string]jape.Handler{"POST /event": func(jc jape.Context) {
var event webhooks.Event
if jc.Decode(&event) != nil {
return
Expand All @@ -132,7 +132,7 @@ func TestEventSubscriber(t *testing.T) {
defer srv.Close()

// register the subscriber
eventsURL := fmt.Sprintf("http://%v/events", srv.Listener.Addr().String())
eventsURL := fmt.Sprintf("http://%v/event", srv.Listener.Addr().String())
go func() {
if err := s.Register(context.Background(), eventsURL); err != nil {
t.Error(err)
Expand Down
2 changes: 1 addition & 1 deletion worker/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func (c *Client) UploadStats() (resp api.UploadStatsResponse, err error) {

// NotifyEvent notifies the worker of an event.
func (c *Client) NotifyEvent(ctx context.Context, e webhooks.Event) (err error) {
err = c.c.WithContext(ctx).POST("/events", e, nil)
err = c.c.WithContext(ctx).POST("/event", e, nil)
return
}

Expand Down
6 changes: 3 additions & 3 deletions worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ func (w *Worker) accountHandlerGET(jc jape.Context) {
jc.Encode(account)
}

func (w *Worker) eventsHandlerPOST(jc jape.Context) {
func (w *Worker) eventHandlerPOST(jc jape.Context) {
var event webhooks.Event
if jc.Decode(&event) != nil {
return
Expand Down Expand Up @@ -1251,7 +1251,7 @@ func (w *Worker) Handler() http.Handler {
"GET /account/:hostkey": w.accountHandlerGET,
"GET /id": w.idHandlerGET,

"POST /events": w.eventsHandlerPOST,
"POST /event": w.eventHandlerPOST,

"GET /memory": w.memoryGET,

Expand Down Expand Up @@ -1283,7 +1283,7 @@ func (w *Worker) Handler() http.Handler {
// Setup register event webhooks that enable the worker cache.
func (w *Worker) Setup(ctx context.Context, apiURL, apiPassword string) error {
go func() {
eventsURL := fmt.Sprintf("%s/events", apiURL)
eventsURL := fmt.Sprintf("%s/event", apiURL)
webhookOpts := []webhooks.HeaderOption{webhooks.WithBasicAuth("", apiPassword)}
if err := w.eventSubscriber.Register(w.shutdownCtx, eventsURL, webhookOpts...); err != nil {
w.logger.Errorw("failed to register webhooks", zap.Error(err))
Expand Down

0 comments on commit 7354e50

Please sign in to comment.