remote_reset_test.go 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. package runtime
  2. import (
  3. "context"
  4. "encoding/json"
  5. "net/http"
  6. "net/http/httptest"
  7. "slices"
  8. "testing"
  9. )
  10. // The master replays a node's reset backlog through the node's bulk endpoint.
  11. func TestRemoteResetClientTrafficsPostsEmailsToBulkEndpoint(t *testing.T) {
  12. var path string
  13. var body struct {
  14. Emails []string `json:"emails"`
  15. }
  16. srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  17. path = r.URL.Path
  18. _ = json.NewDecoder(r.Body).Decode(&body)
  19. w.Header().Set("Content-Type", "application/json")
  20. _, _ = w.Write([]byte(`{"success":true}`))
  21. }))
  22. t.Cleanup(srv.Close)
  23. r := NewRemote(nodeForPlainServer(t, srv, "verify", "tok"), nil)
  24. if err := r.ResetClientTraffics(context.Background(), []string{"a@x", "b@x"}); err != nil {
  25. t.Fatalf("ResetClientTraffics: %v", err)
  26. }
  27. if path != "/panel/api/clients/bulkResetTraffic" || !slices.Equal(body.Emails, []string{"a@x", "b@x"}) {
  28. t.Fatalf("node got %s %v, want /panel/api/clients/bulkResetTraffic [a@x b@x]", path, body.Emails)
  29. }
  30. }