emissary/internal/spec/compare.go

33 lines
669 B
Go

package spec
import (
"github.com/mitchellh/hashstructure/v2"
"github.com/pkg/errors"
)
func Equals(a Spec, b Spec) (bool, error) {
if a.SpecDefinitionName() != b.SpecDefinitionName() {
return false, nil
}
if a.SpecDefinitionVersion() != b.SpecDefinitionVersion() {
return false, nil
}
if a.SpecRevision() != b.SpecRevision() {
return false, nil
}
hashA, err := hashstructure.Hash(a.SpecData(), hashstructure.FormatV2, nil)
if err != nil {
return false, errors.WithStack(err)
}
hashB, err := hashstructure.Hash(b.SpecData(), hashstructure.FormatV2, nil)
if err != nil {
return false, errors.WithStack(err)
}
return hashA == hashB, nil
}