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:
parent
8048e9a585
commit
04f076d780
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue