| 1 | package format |
| 2 | |
| 3 | import ( |
| 4 | "github.com/onsi/ginkgo/v2" |
| 5 | "github.com/onsi/gomega" |
| 6 | |
| 7 | "github.com/nicholas-fedor/shoutrrr/pkg/types" |
| 8 | ) |
| 9 | |
| 10 | var _ = ginkgo.Describe("Prop Key Resolver", func() { |
| 11 | var ( |
| 12 | ts *testStruct |
| 13 | pkr PropKeyResolver |
| 14 | ) |
| 15 | |
| 16 | ginkgo.BeforeEach(func() { |
| 17 | ts = &testStruct{} |
| 18 | pkr = NewPropKeyResolver(ts) |
| 19 | _ = pkr.SetDefaultProps(ts) |
| 20 | }) |
| 21 | ginkgo.Describe("Updating config props from params", func() { |
| 22 | ginkgo.When("a param matches a prop key", func() { |
| 23 | ginkgo.It("should be updated in the config", func() { |
| 24 | err := pkr.UpdateConfigFromParams(nil, &types.Params{"str": "newValue"}) |
| 25 | gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 26 | gomega.Expect(ts.Str).To(gomega.Equal("newValue")) |
| 27 | }) |
| 28 | }) |
| 29 | ginkgo.When("a param does not match a prop key", func() { |
| 30 | ginkgo.It("should report the first error", func() { |
| 31 | err := pkr.UpdateConfigFromParams(nil, &types.Params{"a": "z"}) |
| 32 | gomega.Expect(err).To(gomega.HaveOccurred()) |
| 33 | }) |
| 34 | ginkgo.It("should process the other keys", func() { |
| 35 | _ = pkr.UpdateConfigFromParams( |
| 36 | nil, |
| 37 | &types.Params{"signed": "1", "b": "c", "str": "val"}, |
| 38 | ) |
| 39 | |
| 40 | gomega.Expect(ts.Signed).To(gomega.Equal(1)) |
| 41 | gomega.Expect(ts.Str).To(gomega.Equal("val")) |
| 42 | }) |
| 43 | }) |
| 44 | }) |
| 45 | ginkgo.Describe("Setting default props", func() { |
| 46 | ginkgo.When("a default tag are set for a field", func() { |
| 47 | ginkgo.It("should have that value as default", func() { |
| 48 | gomega.Expect(ts.Str).To(gomega.Equal("notempty")) |
| 49 | }) |
| 50 | }) |
| 51 | ginkgo.When("a default tag have an invalid value", func() { |
| 52 | ginkgo.It("should have that value as default", func() { |
| 53 | tsb := &testStructBadDefault{} |
| 54 | pkr = NewPropKeyResolver(tsb) |
| 55 | err := pkr.SetDefaultProps(tsb) |
| 56 | gomega.Expect(err).To(gomega.HaveOccurred()) |
| 57 | }) |
| 58 | }) |
| 59 | }) |
| 60 | }) |