emissary/internal/spec/compare.go

29 lines
564 B
Go
Raw Permalink Normal View History

2023-03-13 10:44:58 +01:00
package spec
import (
"github.com/mitchellh/hashstructure/v2"
"github.com/pkg/errors"
)
func Equals(a Spec, b Spec) (bool, error) {
if a.SpecName() != b.SpecName() {
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
}