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.
This commit is contained in:
Martin Atkins 2018-09-06 17:17:13 -07:00
parent 8048e9a585
commit 04f076d780
1 changed files with 16 additions and 0 deletions

View File

@ -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 // Instance produces the address for a specific instance of the receiver
// that is idenfied by the given key. // that is idenfied by the given key.
func (r Resource) Instance(key InstanceKey) ResourceInstance { func (r Resource) Instance(key InstanceKey) ResourceInstance {
@ -86,6 +90,10 @@ func (r ResourceInstance) String() string {
return r.Resource.String() + r.Key.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 // Absolute returns an AbsResourceInstance from the receiver and the given module
// instance address. // instance address.
func (r ResourceInstance) Absolute(module ModuleInstance) AbsResourceInstance { 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()) 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 // AbsResourceInstance is an absolute address for a resource instance under a
// given module path. // given module path.
type AbsResourceInstance struct { type AbsResourceInstance struct {
@ -204,6 +216,10 @@ func (r AbsResourceInstance) String() string {
return fmt.Sprintf("%s.%s", r.Module.String(), r.Resource.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 // Less returns true if the receiver should sort before the given other value
// in a sorted list of addresses. // in a sorted list of addresses.
func (r AbsResourceInstance) Less(o AbsResourceInstance) bool { func (r AbsResourceInstance) Less(o AbsResourceInstance) bool {