| 1 |
package format |
| 2 |
|
| 3 |
import ( |
| 4 |
"net/url" |
| 5 |
|
| 6 |
"github.com/onsi/ginkgo/v2" |
| 7 |
"github.com/onsi/gomega" |
| 8 |
) |
| 9 |
|
| 10 |
var _ = ginkgo.Describe("Query Formatter", func() { |
| 11 |
var pkr PropKeyResolver |
| 12 |
|
| 13 |
ginkgo.BeforeEach(func() { |
| 14 |
ts = &testStruct{} |
| 15 |
pkr = NewPropKeyResolver(ts) |
| 16 |
_ = pkr.SetDefaultProps(ts) |
| 17 |
}) |
| 18 |
ginkgo.Describe("Creating a service URL query from a config", func() { |
| 19 |
ginkgo.When("a config property has been changed from default", func() { |
| 20 |
ginkgo.It("should be included in the query string", func() { |
| 21 |
ts.Str = "test" |
| 22 |
query := BuildQuery(&pkr) |
| 23 |
// (pkr, ) |
| 24 |
gomega.Expect(query).To(gomega.Equal("str=test")) |
| 25 |
}) |
| 26 |
}) |
| 27 |
ginkgo.When("a custom query key conflicts with a config property key", func() { |
| 28 |
ginkgo.It("should include both values, with the custom escaped", func() { |
| 29 |
ts.Str = "service" |
| 30 |
customQuery := url.Values{"str": {"custom"}} |
| 31 |
query := BuildQueryWithCustomFields(&pkr, customQuery) |
| 32 |
gomega.Expect(query.Encode()).To(gomega.Equal("__str=custom&str=service")) |
| 33 |
}) |
| 34 |
}) |
| 35 |
}) |
| 36 |
ginkgo.Describe("Setting prop values from query", func() { |
| 37 |
ginkgo.When("a custom query key conflicts with a config property key", func() { |
| 38 |
ginkgo.It( |
| 39 |
"should set the config prop from the regular and return the custom one unescaped", |
| 40 |
func() { |
| 41 |
ts.Str = "service" |
| 42 |
serviceQuery := url.Values{"__str": {"custom"}, "str": {"service"}} |
| 43 |
query, err := SetConfigPropsFromQuery(&pkr, serviceQuery) |
| 44 |
gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 45 |
gomega.Expect(ts.Str).To(gomega.Equal("service")) |
| 46 |
gomega.Expect(query.Get("str")).To(gomega.Equal("custom")) |
| 47 |
}, |
| 48 |
) |
| 49 |
}) |
| 50 |
}) |
| 51 |
}) |