Skip to content

Commit

Permalink
add additional testing
Browse files Browse the repository at this point in the history
  • Loading branch information
piksel committed Apr 29, 2022
1 parent ac59261 commit 1757236
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
13 changes: 10 additions & 3 deletions internal/testutils/config.go
@@ -1,12 +1,12 @@
package testutils

import (
"github.com/containrrr/shoutrrr/pkg/format"
"net/url"

Ω "github.com/onsi/gomega"

"github.com/containrrr/shoutrrr/pkg/format"
"github.com/containrrr/shoutrrr/pkg/types"

Ω "github.com/onsi/gomega"
)

// TestConfigGetInvalidQueryValue tests whether the config returns an error when an invalid query value is requested
Expand All @@ -25,6 +25,13 @@ func TestConfigSetInvalidQueryValue(config types.ServiceConfig, rawInvalidURL st
Ω.ExpectWithOffset(1, err).To(Ω.HaveOccurred())
}

// TestConfigSetInvalidParamValue tests whether the config returns an error when an invalid param key/value is passed
func TestConfigSetInvalidParamValue(config types.ServiceConfig, key string, value string) {
pkr := format.NewPropKeyResolver(config)
err := pkr.UpdateConfigFromParams(config, &types.Params{key: value})
Ω.ExpectWithOffset(1, err).To(Ω.HaveOccurred())
}

// TestConfigGetEnumsCount tests whether the config.Enums returns the expected amount of items
func TestConfigGetEnumsCount(config types.ServiceConfig, expectedCount int) {
enums := config.Enums()
Expand Down
18 changes: 18 additions & 0 deletions internal/testutils/testutils_test.go
Expand Up @@ -10,6 +10,7 @@ import (

func TestTestUtils(t *testing.T) {
RegisterFailHandler(Fail)

RunSpecs(t, "Shoutrrr TestUtils Suite")
}

Expand All @@ -22,4 +23,21 @@ var _ = Describe("the testutils package", func() {
Expect(TestLogger().Prefix()).To(Equal("Test"))
})
})

Describe("Must helpers", func() {
Describe("URLMust", func() {
It("should panic when an invalid URL is passed", func() {
failures := InterceptGomegaFailures(func() { URLMust(":") })
Expect(failures).To(HaveLen(1))
})
})

Describe("JSONRespondMust", func() {
It("should panic when an invalid struct is passed", func() {
notAValidJSONSource := func() {}
failures := InterceptGomegaFailures(func() { JSONRespondMust(200, notAValidJSONSource) })
Expect(failures).To(HaveLen(1))
})
})
})
})
2 changes: 2 additions & 0 deletions pkg/services/bark/bark_test.go
Expand Up @@ -136,6 +136,8 @@ var _ = Describe("the bark service", func() {
testutils.TestConfigGetInvalidQueryValue(&Config{})
testutils.TestConfigSetInvalidQueryValue(&Config{}, "bark://:mock-device@host/?foo=bar")

testutils.TestConfigSetInvalidParamValue(&Config{}, "foo", "bar")

testutils.TestConfigGetEnumsCount(&Config{}, 0)
testutils.TestConfigGetFieldsCount(&Config{}, 9)
})
Expand Down

0 comments on commit 1757236

Please sign in to comment.