Skip to content

Commit

Permalink
fix tests, update go-sentry, add sweepers
Browse files Browse the repository at this point in the history
  • Loading branch information
jianyuan committed Dec 16, 2023
1 parent 4516b2e commit a67bdb8
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-mux v0.13.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.30.0
github.com/jianyuan/go-sentry/v2 v2.5.1-0.20231214003649-288c5a250675
github.com/jianyuan/go-sentry/v2 v2.6.2
golang.org/x/oauth2 v0.15.0
golang.org/x/sync v0.5.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c=
github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo=
github.com/jianyuan/go-sentry/v2 v2.5.1-0.20231214003649-288c5a250675 h1:H6d/M5s+lz1bQahmaSwUYCZ95uiPmw+lJYxFa2axfFo=
github.com/jianyuan/go-sentry/v2 v2.5.1-0.20231214003649-288c5a250675/go.mod h1:YN4yg9u6/b5TfsmXy8OauRu3cyvVXRe1mJY7Pe+/Dt4=
github.com/jianyuan/go-sentry/v2 v2.6.2 h1:tMcsFMjON1IvOtpW1KxZmfdRbW7IXUHY7Kwk6Rmi7oY=
github.com/jianyuan/go-sentry/v2 v2.6.2/go.mod h1:YN4yg9u6/b5TfsmXy8OauRu3cyvVXRe1mJY7Pe+/Dt4=
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down
52 changes: 52 additions & 0 deletions internal/provider/resource_dashboard_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package provider

import (
"context"
"log"
"strings"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/jianyuan/go-sentry/v2/sentry"
"github.com/jianyuan/terraform-provider-sentry/internal/acctest"
)

func init() {
resource.AddTestSweepers("sentry_dashboard", &resource.Sweeper{
Name: "sentry_dashboard",
F: func(r string) error {
ctx := context.Background()

listParams := &sentry.ListCursorParams{}

for {
dashboards, resp, err := acctest.SharedClient.Dashboards.List(ctx, acctest.TestOrganization, listParams)
if err != nil {
return err
}

for _, dashboard := range dashboards {
if !strings.HasPrefix(sentry.StringValue(dashboard.Title), "tf-dashboard") {
continue
}

log.Printf("[INFO] Destroying Dashboard %q", sentry.StringValue(dashboard.Title))

_, err := acctest.SharedClient.Dashboards.Delete(ctx, acctest.TestOrganization, sentry.StringValue(dashboard.ID))
if err != nil {
log.Printf("[ERROR] Failed to destroy Dashboard %q: %s", sentry.StringValue(dashboard.Title), err)
continue
}

log.Printf("[INFO] Dashboard %q has been destroyed.", sentry.StringValue(dashboard.Title))
}

if resp.Cursor == "" {
break
}
listParams.Cursor = resp.Cursor
}

return nil
},
})
}
2 changes: 1 addition & 1 deletion internal/provider/resource_project_inbound_data_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (m *ProjectInboundDataFilterResourceModel) Fill(organization string, projec
m.Active = types.BoolValue(filter.Active.BoolVal)
} else {
subfilterElements := []attr.Value{}
for _, subfilter := range filter.Active.SliceVal {
for _, subfilter := range filter.Active.StringSliceVal {
subfilterElements = append(subfilterElements, types.StringValue(subfilter))
}

Expand Down
52 changes: 52 additions & 0 deletions internal/provider/resource_project_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package provider

import (
"context"
"log"
"strings"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/jianyuan/go-sentry/v2/sentry"
"github.com/jianyuan/terraform-provider-sentry/internal/acctest"
)

func init() {
resource.AddTestSweepers("sentry_project", &resource.Sweeper{
Name: "sentry_project",
F: func(r string) error {
ctx := context.Background()

listParams := &sentry.ListCursorParams{}

for {
projects, resp, err := acctest.SharedClient.Projects.List(ctx, listParams)
if err != nil {
return err
}

for _, project := range projects {
if !strings.HasPrefix(project.Slug, "tf-project") {
continue
}

log.Printf("[INFO] Destroying Project: %s", project.Slug)

_, err := acctest.SharedClient.Projects.Delete(ctx, acctest.TestOrganization, project.Slug)
if err != nil {
log.Printf("[ERROR] Failed to destroy Project %q: %s", project.Slug, err)
continue
}

log.Printf("[INFO] Project %q has been destroyed.", project.Slug)
}

if resp.Cursor == "" {
break
}
listParams.Cursor = resp.Cursor
}

return nil
},
})
}
43 changes: 43 additions & 0 deletions internal/provider/resource_team_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package provider

import (
"context"
"log"
"strings"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/jianyuan/go-sentry/v2/sentry"
"github.com/jianyuan/terraform-provider-sentry/internal/acctest"
)

func init() {
resource.AddTestSweepers("sentry_team", &resource.Sweeper{
Name: "sentry_team",
F: func(r string) error {
ctx := context.Background()

teams, _, err := acctest.SharedClient.Teams.List(ctx, acctest.TestOrganization)
if err != nil {
return err
}

for _, team := range teams {
if !strings.HasPrefix(sentry.StringValue(team.Slug), "tf-team") {
continue
}

log.Printf("[INFO] Destroying Team: %s", sentry.StringValue(team.Slug))

_, err := acctest.SharedClient.Teams.Delete(ctx, acctest.TestOrganization, sentry.StringValue(team.Slug))
if err != nil {
log.Printf("[ERROR] Failed to destroy Team %q: %s", sentry.StringValue(team.Slug), err)
continue
}

log.Printf("[INFO] Team %q has been destroyed.", sentry.StringValue(team.Slug))
}

return nil
},
})
}
10 changes: 8 additions & 2 deletions sentry/resource_sentry_metric_alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func expandMetricAlertTriggerActions(actionList []interface{}) []*sentry.MetricA
}
if v, ok := actionMap["target_identifier"].(string); ok {
if v != "" {
action.TargetIdentifier = sentry.String(v)
action.TargetIdentifier = &sentry.Int64OrString{IsString: true, StringVal: v}
}
}
if v, ok := actionMap["input_channel_id"].(string); ok {
Expand Down Expand Up @@ -401,7 +401,13 @@ func flattenMetricAlertTriggerActions(actions []*sentry.MetricAlertTriggerAction
actionMap["id"] = action.ID
actionMap["type"] = action.Type
actionMap["target_type"] = action.TargetType
actionMap["target_identifier"] = action.TargetIdentifier
if action.TargetIdentifier != nil {
if action.TargetIdentifier.IsInt64 {
actionMap["target_identifier"] = action.TargetIdentifier.Int64Val
} else {
actionMap["target_identifier"] = action.TargetIdentifier.StringVal
}
}
actionMap["input_channel_id"] = action.InputChannelID
actionMap["integration_id"] = action.IntegrationID

Expand Down

0 comments on commit a67bdb8

Please sign in to comment.