Skip to content

Commit

Permalink
Fix linting issues (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
bendbennett committed May 18, 2022
1 parent 3f41ccd commit a670a66
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
9 changes: 6 additions & 3 deletions internal/provider/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta interface{
}

contentType := resp.Header.Get("Content-Type")
if contentType == "" || isContentTypeText(contentType) == false {
if !isContentTypeText(contentType) {
diags = append(diags, diag.Diagnostic{
Severity: diag.Warning,
Summary: fmt.Sprintf("Content-Type is not recognized as a text type, got %q", contentType),
Expand All @@ -100,7 +100,10 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta interface{
responseHeaders[k] = strings.Join(v, ", ")
}

d.Set("body", string(bytes))
if err = d.Set("body", string(bytes)); err != nil {
return append(diags, diag.Errorf("Error setting HTTP response body: %s", err)...)
}

if err = d.Set("response_headers", responseHeaders); err != nil {
return append(diags, diag.Errorf("Error setting HTTP response headers: %s", err)...)
}
Expand All @@ -124,7 +127,7 @@ func isContentTypeText(contentType string) bool {
allowedContentTypes := []*regexp.Regexp{
regexp.MustCompile("^text/.+"),
regexp.MustCompile("^application/json$"),
regexp.MustCompile("^application/samlmetadata\\+xml"),
regexp.MustCompile(`^application/samlmetadata\+xml`),
}

for _, r := range allowedContentTypes {
Expand Down
10 changes: 5 additions & 5 deletions internal/provider/data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,26 +207,26 @@ func setUpMockHttpServer() *TestHttpMock {
w.Header().Add("X-Double", "2")
if r.URL.Path == "/meta_200.txt" {
w.WriteHeader(http.StatusOK)
w.Write([]byte("1.0.0"))
_, _ = w.Write([]byte("1.0.0"))
} else if r.URL.Path == "/restricted/meta_200.txt" {
if r.Header.Get("Authorization") == "Zm9vOmJhcg==" {
w.WriteHeader(http.StatusOK)
w.Write([]byte("1.0.0"))
_, _ = w.Write([]byte("1.0.0"))
} else {
w.WriteHeader(http.StatusForbidden)
}
} else if r.URL.Path == "/utf-8/meta_200.txt" {
w.Header().Set("Content-Type", "text/plain; charset=UTF-8")
w.WriteHeader(http.StatusOK)
w.Write([]byte("1.0.0"))
_, _ = w.Write([]byte("1.0.0"))
} else if r.URL.Path == "/utf-16/meta_200.txt" {
w.Header().Set("Content-Type", "application/json; charset=UTF-16")
w.WriteHeader(http.StatusOK)
w.Write([]byte("\"1.0.0\""))
_, _ = w.Write([]byte("\"1.0.0\""))
} else if r.URL.Path == "/x509/cert.pem" {
w.Header().Set("Content-Type", "application/x-x509-ca-cert")
w.WriteHeader(http.StatusOK)
w.Write([]byte("pem"))
_, _ = w.Write([]byte("pem"))
} else if r.URL.Path == "/meta_404.txt" {
w.WriteHeader(http.StatusNotFound)
} else {
Expand Down
1 change: 1 addition & 0 deletions internal/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

//nolint:unparam // error is always nil
func testProviders() map[string]func() (*schema.Provider, error) {
return map[string]func() (*schema.Provider, error){
"http": func() (*schema.Provider, error) { return New(), nil },
Expand Down

0 comments on commit a670a66

Please sign in to comment.