Skip to content

Commit

Permalink
[NET-7571]
Browse files Browse the repository at this point in the history
- bug fix for SeatGeek: Services function in CT (consul-template) does not update the namespace for each services API call
- opts should be defaulted to the opts at query creation.
- then they should be merged with the opts present in Fetch.
- currently the merge was the other way around.
- ENT test support is not there, so no test cases added as of now.
  • Loading branch information
kkavish committed Feb 6, 2024
1 parent afaa8f6 commit 031d0fb
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
14 changes: 12 additions & 2 deletions dependency/catalog_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,21 @@ func (d *CatalogServicesQuery) Fetch(clients *ClientSet, opts *QueryOptions) (in
default:
}

opts = opts.Merge(&QueryOptions{
// this overrides the query params present in the query
// i.e. overrides the namespace and partition params with ones used the first time
// while creating NewCatalogServicesQuery

// see bug [https://github.com/hashicorp/consul-template/pull/1842#issuecomment-1915723565]
// it should be other way around.
// 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
34 changes: 31 additions & 3 deletions dependency/catalog_services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,41 @@ func TestCatalogServicesQuery_Fetch(t *testing.T) {
},
},
},
// no ENT support as of now.
//{
// "namespace_bar",
// "?ns=bar&partition=default",
// []*CatalogSnippet{
// {
// Name: "consul",
// Tags: ServiceTags([]string{}),
// },
// {
// Name: "foobar-sidecar-proxy",
// Tags: ServiceTags([]string{}),
// },
// {
// Name: "service-meta",
// Tags: ServiceTags([]string{"tag1"}),
// },
// {
// Name: "service-taggedAddresses",
// Tags: ServiceTags([]string{}),
// },
// },
//},
}

var d *CatalogServicesQuery
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)

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

act, _, err := d.Fetch(testClients, nil)
Expand Down

0 comments on commit 031d0fb

Please sign in to comment.