Skip to content

Commit a67bdb8

Browse files
committed
fix tests, update go-sentry, add sweepers
1 parent 4516b2e commit a67bdb8

7 files changed

+159
-6
lines changed

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/hashicorp/terraform-plugin-log v0.9.0
1414
github.com/hashicorp/terraform-plugin-mux v0.13.0
1515
github.com/hashicorp/terraform-plugin-sdk/v2 v2.30.0
16-
github.com/jianyuan/go-sentry/v2 v2.5.1-0.20231214003649-288c5a250675
16+
github.com/jianyuan/go-sentry/v2 v2.6.2
1717
golang.org/x/oauth2 v0.15.0
1818
golang.org/x/sync v0.5.0
1919
)

Diff for: go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl
135135
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
136136
github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c=
137137
github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo=
138-
github.com/jianyuan/go-sentry/v2 v2.5.1-0.20231214003649-288c5a250675 h1:H6d/M5s+lz1bQahmaSwUYCZ95uiPmw+lJYxFa2axfFo=
139-
github.com/jianyuan/go-sentry/v2 v2.5.1-0.20231214003649-288c5a250675/go.mod h1:YN4yg9u6/b5TfsmXy8OauRu3cyvVXRe1mJY7Pe+/Dt4=
138+
github.com/jianyuan/go-sentry/v2 v2.6.2 h1:tMcsFMjON1IvOtpW1KxZmfdRbW7IXUHY7Kwk6Rmi7oY=
139+
github.com/jianyuan/go-sentry/v2 v2.6.2/go.mod h1:YN4yg9u6/b5TfsmXy8OauRu3cyvVXRe1mJY7Pe+/Dt4=
140140
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
141141
github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
142142
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=

Diff for: internal/provider/resource_dashboard_test.go

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package provider
2+
3+
import (
4+
"context"
5+
"log"
6+
"strings"
7+
8+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
9+
"github.com/jianyuan/go-sentry/v2/sentry"
10+
"github.com/jianyuan/terraform-provider-sentry/internal/acctest"
11+
)
12+
13+
func init() {
14+
resource.AddTestSweepers("sentry_dashboard", &resource.Sweeper{
15+
Name: "sentry_dashboard",
16+
F: func(r string) error {
17+
ctx := context.Background()
18+
19+
listParams := &sentry.ListCursorParams{}
20+
21+
for {
22+
dashboards, resp, err := acctest.SharedClient.Dashboards.List(ctx, acctest.TestOrganization, listParams)
23+
if err != nil {
24+
return err
25+
}
26+
27+
for _, dashboard := range dashboards {
28+
if !strings.HasPrefix(sentry.StringValue(dashboard.Title), "tf-dashboard") {
29+
continue
30+
}
31+
32+
log.Printf("[INFO] Destroying Dashboard %q", sentry.StringValue(dashboard.Title))
33+
34+
_, err := acctest.SharedClient.Dashboards.Delete(ctx, acctest.TestOrganization, sentry.StringValue(dashboard.ID))
35+
if err != nil {
36+
log.Printf("[ERROR] Failed to destroy Dashboard %q: %s", sentry.StringValue(dashboard.Title), err)
37+
continue
38+
}
39+
40+
log.Printf("[INFO] Dashboard %q has been destroyed.", sentry.StringValue(dashboard.Title))
41+
}
42+
43+
if resp.Cursor == "" {
44+
break
45+
}
46+
listParams.Cursor = resp.Cursor
47+
}
48+
49+
return nil
50+
},
51+
})
52+
}

Diff for: internal/provider/resource_project_inbound_data_filter.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (m *ProjectInboundDataFilterResourceModel) Fill(organization string, projec
4848
m.Active = types.BoolValue(filter.Active.BoolVal)
4949
} else {
5050
subfilterElements := []attr.Value{}
51-
for _, subfilter := range filter.Active.SliceVal {
51+
for _, subfilter := range filter.Active.StringSliceVal {
5252
subfilterElements = append(subfilterElements, types.StringValue(subfilter))
5353
}
5454

Diff for: internal/provider/resource_project_test.go

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package provider
2+
3+
import (
4+
"context"
5+
"log"
6+
"strings"
7+
8+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
9+
"github.com/jianyuan/go-sentry/v2/sentry"
10+
"github.com/jianyuan/terraform-provider-sentry/internal/acctest"
11+
)
12+
13+
func init() {
14+
resource.AddTestSweepers("sentry_project", &resource.Sweeper{
15+
Name: "sentry_project",
16+
F: func(r string) error {
17+
ctx := context.Background()
18+
19+
listParams := &sentry.ListCursorParams{}
20+
21+
for {
22+
projects, resp, err := acctest.SharedClient.Projects.List(ctx, listParams)
23+
if err != nil {
24+
return err
25+
}
26+
27+
for _, project := range projects {
28+
if !strings.HasPrefix(project.Slug, "tf-project") {
29+
continue
30+
}
31+
32+
log.Printf("[INFO] Destroying Project: %s", project.Slug)
33+
34+
_, err := acctest.SharedClient.Projects.Delete(ctx, acctest.TestOrganization, project.Slug)
35+
if err != nil {
36+
log.Printf("[ERROR] Failed to destroy Project %q: %s", project.Slug, err)
37+
continue
38+
}
39+
40+
log.Printf("[INFO] Project %q has been destroyed.", project.Slug)
41+
}
42+
43+
if resp.Cursor == "" {
44+
break
45+
}
46+
listParams.Cursor = resp.Cursor
47+
}
48+
49+
return nil
50+
},
51+
})
52+
}

Diff for: internal/provider/resource_team_test.go

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package provider
2+
3+
import (
4+
"context"
5+
"log"
6+
"strings"
7+
8+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
9+
"github.com/jianyuan/go-sentry/v2/sentry"
10+
"github.com/jianyuan/terraform-provider-sentry/internal/acctest"
11+
)
12+
13+
func init() {
14+
resource.AddTestSweepers("sentry_team", &resource.Sweeper{
15+
Name: "sentry_team",
16+
F: func(r string) error {
17+
ctx := context.Background()
18+
19+
teams, _, err := acctest.SharedClient.Teams.List(ctx, acctest.TestOrganization)
20+
if err != nil {
21+
return err
22+
}
23+
24+
for _, team := range teams {
25+
if !strings.HasPrefix(sentry.StringValue(team.Slug), "tf-team") {
26+
continue
27+
}
28+
29+
log.Printf("[INFO] Destroying Team: %s", sentry.StringValue(team.Slug))
30+
31+
_, err := acctest.SharedClient.Teams.Delete(ctx, acctest.TestOrganization, sentry.StringValue(team.Slug))
32+
if err != nil {
33+
log.Printf("[ERROR] Failed to destroy Team %q: %s", sentry.StringValue(team.Slug), err)
34+
continue
35+
}
36+
37+
log.Printf("[INFO] Team %q has been destroyed.", sentry.StringValue(team.Slug))
38+
}
39+
40+
return nil
41+
},
42+
})
43+
}

Diff for: sentry/resource_sentry_metric_alert.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ func expandMetricAlertTriggerActions(actionList []interface{}) []*sentry.MetricA
353353
}
354354
if v, ok := actionMap["target_identifier"].(string); ok {
355355
if v != "" {
356-
action.TargetIdentifier = sentry.String(v)
356+
action.TargetIdentifier = &sentry.Int64OrString{IsString: true, StringVal: v}
357357
}
358358
}
359359
if v, ok := actionMap["input_channel_id"].(string); ok {
@@ -401,7 +401,13 @@ func flattenMetricAlertTriggerActions(actions []*sentry.MetricAlertTriggerAction
401401
actionMap["id"] = action.ID
402402
actionMap["type"] = action.Type
403403
actionMap["target_type"] = action.TargetType
404-
actionMap["target_identifier"] = action.TargetIdentifier
404+
if action.TargetIdentifier != nil {
405+
if action.TargetIdentifier.IsInt64 {
406+
actionMap["target_identifier"] = action.TargetIdentifier.Int64Val
407+
} else {
408+
actionMap["target_identifier"] = action.TargetIdentifier.StringVal
409+
}
410+
}
405411
actionMap["input_channel_id"] = action.InputChannelID
406412
actionMap["integration_id"] = action.IntegrationID
407413

0 commit comments

Comments
 (0)