Skip to content

Commit 5168fc5

Browse files
authored
Fix platform validation (#264)
1 parent f6c3a2e commit 5168fc5

File tree

2 files changed

+47
-21
lines changed

2 files changed

+47
-21
lines changed

sentry/resource_sentry_project.go

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -355,29 +355,36 @@ func validatePlatform(i interface{}, path cty.Path) diag.Diagnostics {
355355
return nil
356356
}
357357

358-
url := fmt.Sprintf(
359-
"https://docs.sentry.io/_platforms/%s.json",
360-
strings.Replace(v, "-", "/", 1),
361-
)
362-
resp, err := http.Get(url)
358+
urls := []string{
359+
fmt.Sprintf("https://docs.sentry.io/_platforms/%s.json", v),
360+
fmt.Sprintf(
361+
"https://docs.sentry.io/_platforms/%s.json",
362+
strings.Replace(v, "-", "/", 1),
363+
),
364+
}
363365

364-
if err != nil {
365-
msg := "could not validate the platform at this time"
366-
diagnostics = append(diagnostics, diag.Diagnostic{
367-
Severity: diag.Error,
368-
Summary: msg,
369-
Detail: msg,
370-
AttributePath: path,
371-
})
372-
} else if resp.StatusCode != 200 {
373-
msg := fmt.Sprintf("%s is not a valid platform", v)
374-
diagnostics = append(diagnostics, diag.Diagnostic{
375-
Severity: diag.Error,
376-
Summary: msg,
377-
Detail: msg,
378-
AttributePath: path,
379-
})
366+
for _, url := range urls {
367+
resp, err := http.Get(url)
368+
369+
if err != nil {
370+
msg := "could not validate the platform at this time"
371+
diagnostics = append(diagnostics, diag.Diagnostic{
372+
Severity: diag.Error,
373+
Summary: msg,
374+
Detail: msg,
375+
AttributePath: path,
376+
})
377+
} else if resp.StatusCode == 200 {
378+
return nil
379+
}
380380
}
381381

382+
msg := fmt.Sprintf("%s is not a valid platform", v)
383+
diagnostics = append(diagnostics, diag.Diagnostic{
384+
Severity: diag.Error,
385+
Summary: msg,
386+
Detail: msg,
387+
AttributePath: path,
388+
})
382389
return diagnostics
383390
}

sentry/resource_sentry_team_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,22 @@ resource "sentry_team" "test" {
128128
}
129129
`, teamName)
130130
}
131+
132+
func TestValidatePlatform(t *testing.T) {
133+
for _, tc := range []string{
134+
"javascript-react",
135+
"other",
136+
"python-aiohttp",
137+
"python",
138+
"react-native",
139+
} {
140+
tc := tc
141+
t.Run(tc, func(t *testing.T) {
142+
t.Parallel()
143+
diag := validatePlatform(tc, nil)
144+
if diag.HasError() {
145+
t.Errorf("platform should be valid: %v", tc)
146+
}
147+
})
148+
}
149+
}

0 commit comments

Comments
 (0)