Skip to content

Commit

Permalink
Adding Equal methods
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelattwood committed Jun 13, 2024
1 parent 54eb934 commit 2d5edf4
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
50 changes: 50 additions & 0 deletions surveyor/jetstream_advisories.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,56 @@ func (o *JSAdvisoryConfig) Validate() error {
return fmt.Errorf(strings.Join(errs, ", "))
}

func (o *JSAdvisoryConfig) Equal(c *JSAdvisoryConfig) bool {
if o == nil || c == nil {
return o == c
}

oBytes, err := json.Marshal(o)
if err != nil {
return false
}

cBytes, err := json.Marshal(c)
if err != nil {
return false
}

var oMap, cMap map[string]interface{}

if err := json.Unmarshal([]byte(oBytes), &oMap); err != nil {

Check failure on line 343 in surveyor/jetstream_advisories.go

View workflow job for this annotation

GitHub Actions / test (1.21, macOS-latest)

unnecessary conversion (unconvert)
return false
}

if err := json.Unmarshal([]byte(cBytes), &cMap); err != nil {

Check failure on line 347 in surveyor/jetstream_advisories.go

View workflow job for this annotation

GitHub Actions / test (1.21, macOS-latest)

unnecessary conversion (unconvert)
return false
}

if !reflect.DeepEqual(oMap, cMap) {
return false
}

if o.ExternalAccountConfig == nil || c.ExternalAccountConfig == nil {
if o.ExternalAccountConfig != c.ExternalAccountConfig {
return false
}
}

if o.ExternalAccountConfig != nil {
if *o.ExternalAccountConfig != *c.ExternalAccountConfig {
return false
}
}

for i, opt := range o.NatsOpts {
if fmt.Sprintf("%p", opt) != fmt.Sprintf("%p", c.NatsOpts[i]) {
return false
}
}

return true
}

func (o *JSAdvisoryConfig) copy() *JSAdvisoryConfig {
if o == nil {
return nil
Expand Down
50 changes: 50 additions & 0 deletions surveyor/observation.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,56 @@ func (o *ServiceObsConfig) Validate() error {
return errors.New(strings.Join(errs, ", "))
}

func (o *ServiceObsConfig) Equal(c *ServiceObsConfig) bool {
if o == nil || c == nil {
return o == c
}

oBytes, err := json.Marshal(o)
if err != nil {
return false
}

cBytes, err := json.Marshal(c)
if err != nil {
return false
}

var oMap, cMap map[string]interface{}

if err := json.Unmarshal([]byte(oBytes), &oMap); err != nil {

Check failure on line 219 in surveyor/observation.go

View workflow job for this annotation

GitHub Actions / test (1.21, macOS-latest)

unnecessary conversion (unconvert)
return false
}

if err := json.Unmarshal([]byte(cBytes), &cMap); err != nil {

Check failure on line 223 in surveyor/observation.go

View workflow job for this annotation

GitHub Actions / test (1.21, macOS-latest)

unnecessary conversion (unconvert)
return false
}

if !reflect.DeepEqual(oMap, cMap) {
return false
}

if o.ExternalAccountConfig == nil || c.ExternalAccountConfig == nil {
if o.ExternalAccountConfig != c.ExternalAccountConfig {
return false
}
}

if o.ExternalAccountConfig != nil {
if *o.ExternalAccountConfig != *c.ExternalAccountConfig {
return false
}
}

for i, opt := range o.NatsOpts {
if fmt.Sprintf("%p", opt) != fmt.Sprintf("%p", c.NatsOpts[i]) {
return false
}
}

return true
}

func (o *ServiceObsConfig) copy() *ServiceObsConfig {
if o == nil {
return nil
Expand Down

0 comments on commit 2d5edf4

Please sign in to comment.