In some tests, replace reflection with yaml compare.

This commit is contained in:
jregan
2020-11-22 18:48:32 -08:00
parent b6ae9f80d3
commit 5248fd0cd9
7 changed files with 80 additions and 96 deletions

View File

@@ -5,6 +5,7 @@
package resource
import (
"fmt"
"reflect"
"strings"
@@ -156,9 +157,25 @@ func (r *Resource) copyOtherFields(other *Resource) {
r.nameSuffixes = copyStringSlice(other.nameSuffixes)
}
func (r *Resource) Equals(o *Resource) bool {
return r.ReferencesEqual(o) &&
reflect.DeepEqual(r.kunStr, o.kunStr)
func (r *Resource) ErrIfNotEquals(o *Resource) error {
meYaml, err := r.AsYAML()
if err != nil {
return err
}
otherYaml, err := o.AsYAML()
if err != nil {
return err
}
if !r.ReferencesEqual(o) {
return fmt.Errorf("references unequal")
}
if string(meYaml) != string(otherYaml) {
return fmt.Errorf("--- self:\n"+
"%s\n"+
"--- other:\n"+
"%s\n", meYaml, otherYaml)
}
return nil
}
func (r *Resource) ReferencesEqual(o *Resource) bool {