Add Equal func for Status struct
This commit is contained in:
@@ -25,6 +25,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/client-go/informers"
|
||||
@@ -180,6 +182,21 @@ func (s *Status) AsError() error {
|
||||
return errors.New(s.Message())
|
||||
}
|
||||
|
||||
// Equal checks equality of two statuses. This is useful for testing with
|
||||
// cmp.Equal.
|
||||
func (s *Status) Equal(x *Status) bool {
|
||||
if s == nil || x == nil {
|
||||
return s.IsSuccess() && x.IsSuccess()
|
||||
}
|
||||
if s.code != x.code {
|
||||
return false
|
||||
}
|
||||
if s.code == Error {
|
||||
return cmp.Equal(s.err, x.err, cmpopts.EquateErrors())
|
||||
}
|
||||
return cmp.Equal(s.reasons, x.reasons)
|
||||
}
|
||||
|
||||
// NewStatus makes a Status out of the given arguments and returns its pointer.
|
||||
func NewStatus(code Code, reasons ...string) *Status {
|
||||
s := &Status{
|
||||
|
Reference in New Issue
Block a user