emissary/internal/spec/compare.go
William Petit f612721b4e
All checks were successful
arcad/emissary/pipeline/head This commit looks good
arcad/emissary/pipeline/pr-master This commit looks good
feat: add spec definition api with versioning
2024-03-12 16:22:35 +01:00

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
}