|
| 1 | +// |
| 2 | +// DISCLAIMER |
| 3 | +// |
| 4 | +// Copyright 2018 ArangoDB GmbH, Cologne, Germany |
| 5 | +// |
| 6 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +// you may not use this file except in compliance with the License. |
| 8 | +// You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | +// |
| 18 | +// Copyright holder is ArangoDB GmbH, Cologne, Germany |
| 19 | +// |
| 20 | +// Author Ewout Prangsma |
| 21 | +// |
| 22 | + |
| 23 | +package v1alpha |
| 24 | + |
| 25 | +import ( |
| 26 | + "testing" |
| 27 | + "time" |
| 28 | + |
| 29 | + "github.com/stretchr/testify/assert" |
| 30 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 31 | +) |
| 32 | + |
| 33 | +// TestMemberStatusRecentTerminations tests the functions related to MemberStatus.RecentTerminations. |
| 34 | +func TestMemberStatusRecentTerminations(t *testing.T) { |
| 35 | + relTime := func(delta time.Duration) metav1.Time { |
| 36 | + return metav1.Time{Time: time.Now().Add(delta)} |
| 37 | + } |
| 38 | + |
| 39 | + s := MemberStatus{} |
| 40 | + assert.Equal(t, 0, s.RecentTerminationsSince(time.Now().Add(-time.Hour))) |
| 41 | + assert.Equal(t, 0, s.RemoveTerminationsBefore(time.Now())) |
| 42 | + |
| 43 | + s.RecentTerminations = []metav1.Time{metav1.Now()} |
| 44 | + assert.Equal(t, 1, s.RecentTerminationsSince(time.Now().Add(-time.Minute))) |
| 45 | + assert.Equal(t, 0, s.RecentTerminationsSince(time.Now().Add(time.Minute))) |
| 46 | + assert.Equal(t, 0, s.RemoveTerminationsBefore(time.Now().Add(-time.Hour))) |
| 47 | + |
| 48 | + s.RecentTerminations = []metav1.Time{relTime(-time.Hour), relTime(-time.Minute), relTime(time.Minute)} |
| 49 | + assert.Equal(t, 3, s.RecentTerminationsSince(time.Now().Add(-time.Hour*2))) |
| 50 | + assert.Equal(t, 2, s.RecentTerminationsSince(time.Now().Add(-time.Minute*2))) |
| 51 | + assert.Equal(t, 2, s.RemoveTerminationsBefore(time.Now())) |
| 52 | + assert.Len(t, s.RecentTerminations, 1) |
| 53 | +} |
0 commit comments