-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Enable/disable spike protection
- Loading branch information
Showing
3 changed files
with
87 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package sentry | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
type SpikeProtectionsService service | ||
|
||
type SpikeProtectionParams struct { | ||
Projects []string `json:"projects"` | ||
} | ||
|
||
func (s *SpikeProtectionsService) Enable(ctx context.Context, organizationSlug string, params *SpikeProtectionParams) (*Response, error) { | ||
u := fmt.Sprintf("0/organizations/%v/spike-protections/", organizationSlug) | ||
req, err := s.client.NewRequest(http.MethodPost, u, params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return s.client.Do(ctx, req, nil) | ||
} | ||
|
||
func (s *SpikeProtectionsService) Disable(ctx context.Context, organizationSlug string, params *SpikeProtectionParams) (*Response, error) { | ||
u := fmt.Sprintf("0/organizations/%v/spike-protections/", organizationSlug) | ||
req, err := s.client.NewRequest(http.MethodDelete, u, params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return s.client.Do(ctx, req, nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package sentry | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSpikeProtectionsService_Enable(t *testing.T) { | ||
client, mux, _, teardown := setup() | ||
defer teardown() | ||
|
||
mux.HandleFunc("/api/0/organizations/organization_slug/spike-protections/", func(w http.ResponseWriter, r *http.Request) { | ||
assertMethod(t, http.MethodPost, r) | ||
assertPostJSON(t, map[string]interface{}{ | ||
"projects": []interface{}{"$all"}, | ||
}, r) | ||
}) | ||
|
||
params := &SpikeProtectionParams{ | ||
Projects: []string{"$all"}, | ||
} | ||
ctx := context.Background() | ||
_, err := client.SpikeProtections.Enable(ctx, "organization_slug", params) | ||
assert.NoError(t, err) | ||
} | ||
|
||
func TestSpikeProtectionsService_Disable(t *testing.T) { | ||
client, mux, _, teardown := setup() | ||
defer teardown() | ||
|
||
mux.HandleFunc("/api/0/organizations/organization_slug/spike-protections/", func(w http.ResponseWriter, r *http.Request) { | ||
assertMethod(t, http.MethodDelete, r) | ||
assertPostJSON(t, map[string]interface{}{ | ||
"projects": []interface{}{"$all"}, | ||
}, r) | ||
}) | ||
|
||
params := &SpikeProtectionParams{ | ||
Projects: []string{"$all"}, | ||
} | ||
ctx := context.Background() | ||
_, err := client.SpikeProtections.Disable(ctx, "organization_slug", params) | ||
assert.NoError(t, err) | ||
} |