| 1 |
package homeassistant |
| 2 |
|
| 3 |
import ( |
| 4 |
"bytes" |
| 5 |
"io" |
| 6 |
"net/http" |
| 7 |
"net/url" |
| 8 |
"testing" |
| 9 |
|
| 10 |
"github.com/onsi/ginkgo/v2" |
| 11 |
"github.com/onsi/gomega" |
| 12 |
|
| 13 |
"github.com/nicholas-fedor/shoutrrr/pkg/types" |
| 14 |
) |
| 15 |
|
| 16 |
type noOpLogger struct{} |
| 17 |
|
| 18 |
type stubHTTPClient struct { |
| 19 |
req *http.Request |
| 20 |
body []byte |
| 21 |
resp *http.Response |
| 22 |
err error |
| 23 |
} |
| 24 |
|
| 25 |
var _ types.StdLogger = (*noOpLogger)(nil) |
| 26 |
|
| 27 |
func (*noOpLogger) Print(_ ...any) {} |
| 28 |
func (*noOpLogger) Printf(_ string, _ ...any) {} |
| 29 |
func (*noOpLogger) Println(_ ...any) {} |
| 30 |
|
| 31 |
func (c *stubHTTPClient) Do(req *http.Request) (*http.Response, error) { |
| 32 |
c.req = req |
| 33 |
|
| 34 |
if req.Body != nil { |
| 35 |
body, err := io.ReadAll(req.Body) |
| 36 |
if err == nil { |
| 37 |
c.body = body |
| 38 |
req.Body = io.NopCloser(bytes.NewReader(body)) |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
if c.err != nil { |
| 43 |
return nil, c.err |
| 44 |
} |
| 45 |
|
| 46 |
if c.resp != nil { |
| 47 |
return c.resp, nil |
| 48 |
} |
| 49 |
|
| 50 |
return &http.Response{ |
| 51 |
StatusCode: http.StatusOK, |
| 52 |
Status: "200 OK", |
| 53 |
Body: io.NopCloser(bytes.NewReader([]byte(`[]`))), |
| 54 |
Header: make(http.Header), |
| 55 |
}, nil |
| 56 |
} |
| 57 |
|
| 58 |
func mustParseURL(raw string) *url.URL { |
| 59 |
parsed, err := url.Parse(raw) |
| 60 |
gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 61 |
|
| 62 |
return parsed |
| 63 |
} |
| 64 |
|
| 65 |
func TestHomeAssistant(t *testing.T) { //nolint:paralleltest // Ginkgo manages its own parallelization |
| 66 |
gomega.RegisterFailHandler(ginkgo.Fail) |
| 67 |
ginkgo.RunSpecs(t, "Home Assistant Suite") |
| 68 |
} |