Debian Codegraph @

internal/testutils/config.go

raw
1 package testutils
2
3 import (
4 "net/url"
5
6 "github.com/onsi/gomega"
7
8 "github.com/nicholas-fedor/shoutrrr/pkg/format"
9 "github.com/nicholas-fedor/shoutrrr/pkg/types"
10 )
11
12 // TestConfigGetInvalidQueryValue tests whether the config returns
13 // an error when an invalid query value is requested.
14 func TestConfigGetInvalidQueryValue(config types.ServiceConfig) {
15 value, err := format.GetConfigQueryResolver(config).Get("invalid query var")
16 gomega.ExpectWithOffset(1, value).To(gomega.BeEmpty())
17 gomega.ExpectWithOffset(1, err).To(gomega.HaveOccurred())
18 }
19
20 // TestConfigSetInvalidQueryValue tests whether the config returns
21 // an error when a URL with an invalid query value is parsed.
22 func TestConfigSetInvalidQueryValue(config types.ServiceConfig, rawInvalidURL string) {
23 invalidURL, err := url.Parse(rawInvalidURL)
24 gomega.ExpectWithOffset(1, err).
25 ToNot(gomega.HaveOccurred(), "the test URL did not parse correctly")
26
27 err = config.SetURL(invalidURL)
28 gomega.ExpectWithOffset(1, err).To(gomega.HaveOccurred())
29 }
30
31 // TestConfigSetDefaultValues tests whether setting the default values
32 // can be set for an empty config without any errors.
33 func TestConfigSetDefaultValues(config types.ServiceConfig) {
34 pkr := format.NewPropKeyResolver(config)
35 gomega.ExpectWithOffset(1, pkr.SetDefaultProps(config)).To(gomega.Succeed())
36 }
37
38 // TestConfigGetEnumsCount tests whether the config.Enums returns the expected amount of items.
39 func TestConfigGetEnumsCount(config types.ServiceConfig, expectedCount int) {
40 enums := config.Enums()
41 gomega.ExpectWithOffset(1, enums).To(gomega.HaveLen(expectedCount))
42 }
43
44 // TestConfigGetFieldsCount tests whether the config.QueryFields return the expected amount of fields.
45 func TestConfigGetFieldsCount(config types.ServiceConfig, expectedCount int) {
46 fields := format.GetConfigQueryResolver(config).QueryFields()
47 gomega.ExpectWithOffset(1, fields).To(gomega.HaveLen(expectedCount))
48 }