Skip to content

Commit 187d468

Browse files
committed
Added unit tests
1 parent 892c41a commit 187d468

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Copyright 2022 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1_test
18+
19+
import (
20+
. "github.com/onsi/ginkgo/v2"
21+
. "github.com/onsi/gomega"
22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta1"
24+
"time"
25+
)
26+
27+
var _ = Describe("CloudStackMachine types", func() {
28+
var cloudStackMachine infrav1.CloudStackMachine
29+
30+
BeforeEach(func() { // Reset test vars to initial state.
31+
cloudStackMachine = infrav1.CloudStackMachine{}
32+
})
33+
34+
Context("When calculating time since state change", func() {
35+
It("Return the correct value when the last state update time is known", func() {
36+
delta := time.Duration(10 * time.Minute)
37+
lastUpdated := time.Now().Add(-delta)
38+
cloudStackMachine.Status.InstanceStateLastUpdated = metav1.NewTime(lastUpdated)
39+
Ω(cloudStackMachine.Status.TimeSinceLastStateChange()).Should(BeNumerically("~", delta, time.Second))
40+
})
41+
42+
It("Return a negative value when the last state update time is unknown", func() {
43+
Ω(cloudStackMachine.Status.TimeSinceLastStateChange()).Should(BeNumerically("<", 0))
44+
})
45+
})
46+
})

0 commit comments

Comments
 (0)