Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NET-9468, NET-9902] Differentiate the ListExportedServicesQuery dependency based on the provided partition #1949

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dependency/consul_exported_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (c *ListExportedServicesQuery) CanShare() bool {
}

func (c *ListExportedServicesQuery) String() string {
return exportedServicesEndpointLabel
return fmt.Sprintf("%s(%s)", exportedServicesEndpointLabel, c.partition)
}

func (c *ListExportedServicesQuery) Stop() {
Expand Down
9 changes: 9 additions & 0 deletions dependency/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,16 @@ const (
type Dependency interface {
Fetch(*ClientSet, *QueryOptions) (interface{}, *ResponseMetadata, error)
CanShare() bool

// String is used to uniquely identify a dependency. If a dependency receives arguments and
// may be used multiple times w/ different args, then it should make sure to differentiate
// itself based on those args; otherwise, only one instance of the dependency will be created.
//
// For example: Calling the exportedServices func multiple times in a template for different
// partitions will result in the first partition provided being used repeatedly - regardless of the
// partition provided in later calls - if the partition name is not included in the output of String.
String() string

Stop()
Type() Type
}
Expand Down
18 changes: 18 additions & 0 deletions template/funcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,21 @@ func Test_hmacSHA256Hex(t *testing.T) {
})
}
}

// Test_exportedServicesFunc verifies that calling exportedServices w/ a
// different partition tracks an additional dependency
func Test_exportedServicesFunc(t *testing.T) {
var used, missing dep.Set

f := exportedServicesFunc(NewBrain(), &used, &missing)

_, err := f("default")
require.NoError(t, err)
assert.Equal(t, "list.exportedServices(default)", used.String())
assert.Equal(t, "list.exportedServices(default)", missing.String())

_, err = f("ap1")
require.NoError(t, err)
assert.Equal(t, "list.exportedServices(default), list.exportedServices(ap1)", used.String())
assert.Equal(t, "list.exportedServices(default), list.exportedServices(ap1)", missing.String())
}
Loading