fix lint errors
All checks were successful
Lint / golangci-lint (push) Successful in 9m57s
Declarative Tests / test (push) Successful in 1m25s

This commit is contained in:
Matthew Rich 2024-04-10 13:27:34 -07:00
parent 11a55e27d0
commit adea95972d
2 changed files with 6 additions and 4 deletions

View File

@ -29,14 +29,14 @@ func HTTPFactory(u *url.URL) Resource {
type HTTPHeader struct { type HTTPHeader struct {
Name string `yaml:"name" json:"name"` Name string `yaml:"name" json:"name"`
Value string `yaml:"value" json"value"` Value string `yaml:"value" json:"value"`
} }
// Manage the state of an HTTP endpoint // Manage the state of an HTTP endpoint
type HTTP struct { type HTTP struct {
client *http.Client `yaml:"-" json:"-"` client *http.Client `yaml:"-" json:"-"`
Endpoint string `yaml:"endpoint" json:"endpoint"` Endpoint string `yaml:"endpoint" json:"endpoint"`
Headers []HTTPHeader `yaml:"headers,omitempty", json:"headers,omitempty"` Headers []HTTPHeader `yaml:"headers,omitempty" json:"headers,omitempty"`
Body string `yaml:"body,omitempty" json:"body,omitempty"` Body string `yaml:"body,omitempty" json:"body,omitempty"`
State string `yaml:"state" json:"state"` State string `yaml:"state" json:"state"`
} }
@ -107,10 +107,10 @@ func (h *HTTP) Create() error {
req.Header.Add(header.Name, header.Value) req.Header.Add(header.Name, header.Value)
} }
resp, err := h.client.Do(req) resp, err := h.client.Do(req)
defer resp.Body.Close()
if err != nil { if err != nil {
return err return err
} }
defer resp.Body.Close()
return err return err
} }

View File

@ -44,12 +44,14 @@ func TestHTTPRead(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
assert.Equal(t, req.URL.String(), "/resource/user/foo") assert.Equal(t, req.URL.String(), "/resource/user/foo")
rw.Write([]byte(` n,e := rw.Write([]byte(`
type: "user" type: "user"
attributes: attributes:
name: "foo" name: "foo"
gecos: "foo user" gecos: "foo user"
`)) `))
assert.Nil(t, e)
assert.Greater(t, n, 0)
})) }))
defer server.Close() defer server.Close()