mirror of
https://github.com/arangodb/kube-arangodb.git
synced 2024-12-14 11:57:37 +00:00
Fix equality check for Plan Action (#1373)
It was returning false even for a.Equals(a) because of wrong check in times.go
This commit is contained in:
parent
686559654d
commit
63a65d856c
2 changed files with 57 additions and 1 deletions
|
@ -23,8 +23,10 @@ package v1
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_Action_Marshal(t *testing.T) {
|
func Test_Action_Marshal(t *testing.T) {
|
||||||
|
@ -34,3 +36,54 @@ func Test_Action_Marshal(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, `{"id":"","type":"","creationTime":null}`, string(data))
|
require.Equal(t, `{"id":"","type":"","creationTime":null}`, string(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_Action_Equal(t *testing.T) {
|
||||||
|
a := Action{
|
||||||
|
ID: "9ktKQsBAqe5Ra8ZJ",
|
||||||
|
SetID: "",
|
||||||
|
Type: ActionTypeAddMember,
|
||||||
|
MemberID: "",
|
||||||
|
Group: 2,
|
||||||
|
CreationTime: meta.Time{
|
||||||
|
Time: time.Date(2023, time.August, 1, 20, 6, 53, 0, time.UTC),
|
||||||
|
},
|
||||||
|
StartTime: nil,
|
||||||
|
Reason: "",
|
||||||
|
Image: "",
|
||||||
|
Params: nil,
|
||||||
|
Locals: nil,
|
||||||
|
TaskID: "",
|
||||||
|
Architecture: "",
|
||||||
|
Progress: "",
|
||||||
|
}
|
||||||
|
b := Action{
|
||||||
|
ID: "9ktKQsBAqe5Ra8ZJ",
|
||||||
|
SetID: "",
|
||||||
|
Type: ActionTypeAddMember,
|
||||||
|
MemberID: "",
|
||||||
|
Group: 2,
|
||||||
|
CreationTime: meta.Time{
|
||||||
|
Time: time.Date(2023, time.August, 1, 20, 6, 53, 0, time.UTC),
|
||||||
|
},
|
||||||
|
StartTime: nil,
|
||||||
|
Reason: "",
|
||||||
|
Image: "",
|
||||||
|
Params: nil,
|
||||||
|
Locals: nil,
|
||||||
|
TaskID: "",
|
||||||
|
Architecture: "",
|
||||||
|
Progress: "",
|
||||||
|
}
|
||||||
|
|
||||||
|
require.True(t, a.Equal(a))
|
||||||
|
require.True(t, a.Equal(b))
|
||||||
|
require.True(t, b.Equal(a))
|
||||||
|
require.True(t, b.Equal(b))
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
|
a.StartTime = &meta.Time{Time: now}
|
||||||
|
require.True(t, a.Equal(a))
|
||||||
|
require.False(t, a.Equal(b))
|
||||||
|
require.False(t, b.Equal(a))
|
||||||
|
require.True(t, b.Equal(b))
|
||||||
|
}
|
||||||
|
|
|
@ -35,8 +35,11 @@ func TimeCompareEqual(a, b meta.Time) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TimeCompareEqualPointer compares two times, allowing an error of 1s
|
// TimeCompareEqualPointer compares two times, allowing an error of 1s
|
||||||
|
// Returns true if both pointers are nil
|
||||||
func TimeCompareEqualPointer(a, b *meta.Time) bool {
|
func TimeCompareEqualPointer(a, b *meta.Time) bool {
|
||||||
if a == nil || b == nil {
|
if a == nil && b == nil {
|
||||||
|
return true
|
||||||
|
} else if a == nil || b == nil {
|
||||||
return false
|
return false
|
||||||
} else if a == b {
|
} else if a == b {
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Reference in a new issue