From 04f076d780102b720439a81514bae2105665c30d Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Thu, 6 Sep 2018 17:17:13 -0700 Subject: [PATCH] addrs: Implement Equal for resource address types This is primarily to get good default behavior for test helpers that do deep comparison of values, but may also be convenient elsewhere. --- addrs/resource.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/addrs/resource.go b/addrs/resource.go index 526a309a0..2d7ebfa27 100644 --- a/addrs/resource.go +++ b/addrs/resource.go @@ -28,6 +28,10 @@ func (r Resource) String() string { } } +func (r Resource) Equal(other Resource) bool { + return r.String() == other.String() +} + // Instance produces the address for a specific instance of the receiver // that is idenfied by the given key. func (r Resource) Instance(key InstanceKey) ResourceInstance { @@ -86,6 +90,10 @@ func (r ResourceInstance) String() string { return r.Resource.String() + r.Key.String() } +func (r ResourceInstance) Equal(other ResourceInstance) bool { + return r.String() == other.String() +} + // Absolute returns an AbsResourceInstance from the receiver and the given module // instance address. func (r ResourceInstance) Absolute(module ModuleInstance) AbsResourceInstance { @@ -149,6 +157,10 @@ func (r AbsResource) String() string { return fmt.Sprintf("%s.%s", r.Module.String(), r.Resource.String()) } +func (r AbsResource) Equal(other AbsResource) bool { + return r.String() == other.String() +} + // AbsResourceInstance is an absolute address for a resource instance under a // given module path. type AbsResourceInstance struct { @@ -204,6 +216,10 @@ func (r AbsResourceInstance) String() string { return fmt.Sprintf("%s.%s", r.Module.String(), r.Resource.String()) } +func (r AbsResourceInstance) Equal(other AbsResourceInstance) bool { + return r.String() == other.String() +} + // Less returns true if the receiver should sort before the given other value // in a sorted list of addresses. func (r AbsResourceInstance) Less(o AbsResourceInstance) bool {