| 1 |
package e2e_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"os" |
| 5 |
|
| 6 |
"github.com/onsi/ginkgo/v2" |
| 7 |
"github.com/onsi/gomega" |
| 8 |
|
| 9 |
"github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy" |
| 10 |
) |
| 11 |
|
| 12 |
var _ = ginkgo.Describe("ntfy E2E Config Tests", func() { |
| 13 |
ginkgo.When("running e2e tests against a real ntfy server", func() { |
| 14 |
ginkgo.BeforeEach(func() { |
| 15 |
if !isNtfyServerAvailable() { |
| 16 |
ginkgo.Skip("ntfy server not available, skipping e2e tests") |
| 17 |
} |
| 18 |
}) |
| 19 |
|
| 20 |
ginkgo.It("should initialize with default configuration", func() { |
| 21 |
serviceURLStr := buildServiceURL() |
| 22 |
service := initializeService(serviceURLStr) |
| 23 |
|
| 24 |
gomega.Expect(service.Config.Topic).NotTo(gomega.BeEmpty()) |
| 25 |
gomega.Expect(service.Config.Host).NotTo(gomega.BeEmpty()) |
| 26 |
}) |
| 27 |
|
| 28 |
ginkgo.It("should initialize with credentials from URL", func() { |
| 29 |
serviceURLStr := buildServiceURL() |
| 30 |
service := initializeService(serviceURLStr) |
| 31 |
|
| 32 |
username := os.Getenv("SHOUTRRR_NTFY_USERNAME") |
| 33 |
password := os.Getenv("SHOUTRRR_NTFY_PASSWORD") |
| 34 |
|
| 35 |
if username != "" { |
| 36 |
gomega.Expect(service.Config.Username).To(gomega.Equal(username)) |
| 37 |
} |
| 38 |
|
| 39 |
if password != "" { |
| 40 |
gomega.Expect(service.Config.Password).To(gomega.Equal(password)) |
| 41 |
} |
| 42 |
}) |
| 43 |
|
| 44 |
ginkgo.It("should initialize with DisableTLS when configured", func() { |
| 45 |
previous, hadPrevious := os.LookupEnv("SHOUTRRR_NTFY_DISABLE_TLS") |
| 46 |
_ = os.Setenv("SHOUTRRR_NTFY_DISABLE_TLS", "true") |
| 47 |
|
| 48 |
defer func() { |
| 49 |
if hadPrevious { |
| 50 |
_ = os.Setenv("SHOUTRRR_NTFY_DISABLE_TLS", previous) |
| 51 |
} else { |
| 52 |
_ = os.Unsetenv("SHOUTRRR_NTFY_DISABLE_TLS") |
| 53 |
} |
| 54 |
}() |
| 55 |
|
| 56 |
serviceURLStr := buildServiceURL() |
| 57 |
service := initializeService(serviceURLStr) |
| 58 |
|
| 59 |
gomega.Expect(service.Config.DisableTLS).To(gomega.BeTrue()) |
| 60 |
gomega.Expect(service.Config.Scheme).To(gomega.Equal("http")) |
| 61 |
}) |
| 62 |
|
| 63 |
ginkgo.It("should initialize with priority from URL", func() { |
| 64 |
serviceURLStr := addQueryParam(buildServiceURL(), "priority", "Max") |
| 65 |
service := initializeService(serviceURLStr) |
| 66 |
|
| 67 |
gomega.Expect(service.Config.Priority.String()).To(gomega.Equal("Max")) |
| 68 |
}) |
| 69 |
|
| 70 |
ginkgo.It("should initialize with markdown enabled from URL", func() { |
| 71 |
serviceURLStr := addQueryParam(buildServiceURL(), "markdown", "yes") |
| 72 |
service := initializeService(serviceURLStr) |
| 73 |
|
| 74 |
gomega.Expect(service.Config.Markdown).To(gomega.BeTrue()) |
| 75 |
}) |
| 76 |
|
| 77 |
ginkgo.It("should initialize with tags from URL", func() { |
| 78 |
serviceURLStr := addQueryParam(buildServiceURL(), "tags", "warning,skull") |
| 79 |
service := initializeService(serviceURLStr) |
| 80 |
|
| 81 |
gomega.Expect(service.Config.Tags).To(gomega.ConsistOf("warning", "skull")) |
| 82 |
}) |
| 83 |
|
| 84 |
ginkgo.It("should initialize with title from URL", func() { |
| 85 |
serviceURLStr := addQueryParam(buildServiceURL(), "title", "MyTitle") |
| 86 |
service := initializeService(serviceURLStr) |
| 87 |
|
| 88 |
gomega.Expect(service.Config.Title).To(gomega.Equal("MyTitle")) |
| 89 |
}) |
| 90 |
}) |
| 91 |
|
| 92 |
ginkgo.When("no server is configured", func() { |
| 93 |
ginkgo.It("should return the correct service ID", func() { |
| 94 |
service := &ntfy.Service{} |
| 95 |
gomega.Expect(service.GetID()).To(gomega.Equal("ntfy")) |
| 96 |
}) |
| 97 |
}) |
| 98 |
}) |