Skip to content

Commit

Permalink
Merge pull request #1874 from hashicorp/NET-7571
Browse files Browse the repository at this point in the history
[NET-7571]SeatGeek
  • Loading branch information
kkavish authored Feb 7, 2024
2 parents afaa8f6 + 5b66da6 commit 5fbf750
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
NEW FEATURES:
* Add support for listing Consul peers [NET-6966](https://hashicorp.atlassian.net/browse/NET-6966)

BUG FIXES:
* Fetch services query not overriding opts correctly [NET-7571](https://hashicorp.atlassian.net/browse/NET-7571)

## v0.36.0 (January 3, 2024)

IMPROVEMENTS:
Expand Down
10 changes: 8 additions & 2 deletions dependency/catalog_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,17 @@ func (d *CatalogServicesQuery) Fetch(clients *ClientSet, opts *QueryOptions) (in
default:
}

opts = opts.Merge(&QueryOptions{
// this overrides the query params present in the query with ones present while creating the query
// see bug [https://github.com/hashicorp/consul-template/pull/1842#issuecomment-1915723565]
// default to the query params present while creating NewCatalogServicesQuery
// and then merge with the query params present in the query
defaultOpts := &QueryOptions{
Datacenter: d.dc,
ConsulPartition: d.partition,
ConsulNamespace: d.namespace,
})
}

opts = defaultOpts.Merge(opts)

log.Printf("[TRACE] %s: GET %s", d, &url.URL{
Path: "/v1/catalog/services",
Expand Down
13 changes: 11 additions & 2 deletions dependency/catalog_services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,14 @@ func TestCatalogServicesQuery_Fetch(t *testing.T) {
cases := []struct {
name string
i string
opts *QueryOptions
exp []*CatalogSnippet
err bool
}{
{
"all",
"",
nil,
[]*CatalogSnippet{
{
Name: "consul",
Expand All @@ -123,21 +126,27 @@ func TestCatalogServicesQuery_Fetch(t *testing.T) {
Tags: ServiceTags([]string{}),
},
},
false,
},
}

for i, tc := range cases {
t.Run(fmt.Sprintf("%d_%s", i, tc.name), func(t *testing.T) {

d, err := NewCatalogServicesQuery(tc.i)
if err != nil {
t.Fatal(err)
}

act, _, err := d.Fetch(testClients, nil)
if err != nil {
act, _, err := d.Fetch(testClients, tc.opts)
if (err != nil) != tc.err {
t.Fatal(err)
}

if act == nil && tc.err {
return
}

assert.Equal(t, tc.exp, act)
})
}
Expand Down

0 comments on commit 5fbf750

Please sign in to comment.