Skip to content

Commit 51f2364

Browse files
author
Joshua Reed
committed
Broke dummies out into two versions. Tests almost working again.
1 parent a66b32f commit 51f2364

36 files changed

+437
-228
lines changed

api/v1beta1/cloudstackcluster_webhook_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
. "github.com/onsi/ginkgo/v2"
2323
. "github.com/onsi/gomega"
2424
infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta1"
25-
"sigs.k8s.io/cluster-api-provider-cloudstack/test/dummies"
25+
dummies "sigs.k8s.io/cluster-api-provider-cloudstack/test/dummies/v1beta1"
2626
)
2727

2828
var _ = Describe("CloudStackCluster webhooks", func() {

api/v1beta2/cloudstackcluster_webhook_test.go renamed to api/v1beta1/cloudstackcluster_webhook_test.go.bak

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package v1beta2_test
17+
package v1beta1_test
1818

1919
import (
2020
"context"
2121

2222
. "github.com/onsi/ginkgo/v2"
2323
. "github.com/onsi/gomega"
2424
infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta1"
25-
"sigs.k8s.io/cluster-api-provider-cloudstack/test/dummies"
25+
"sigs.k8s.io/cluster-api-provider-cloudstack/test/v1beta1/dummies"
2626
)
2727

2828
var _ = Describe("CloudStackCluster webhooks", func() {

api/v1beta1/cloudstackfailuredomain_types.go

Lines changed: 0 additions & 68 deletions
This file was deleted.

api/v1beta1/cloudstackmachine_types_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ limitations under the License.
1717
package v1beta1_test
1818

1919
import (
20+
"time"
21+
2022
. "github.com/onsi/ginkgo/v2"
2123
. "github.com/onsi/gomega"
2224
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2325
infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta1"
24-
"time"
2526
)
2627

2728
var _ = Describe("CloudStackMachine types", func() {
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+
})

api/v1beta1/cloudstackmachine_webhook_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"context"
2121

2222
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta1"
23-
"sigs.k8s.io/cluster-api-provider-cloudstack/test/dummies"
23+
dummies "sigs.k8s.io/cluster-api-provider-cloudstack/test/dummies/v1beta1"
2424

2525
. "github.com/onsi/ginkgo/v2"
2626
. "github.com/onsi/gomega"

api/v1beta2/cloudstackmachine_webhook_test.go renamed to api/v1beta1/cloudstackmachine_webhook_test.go.bak

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package v1beta2_test
17+
package v1beta1_test
1818

1919
import (
2020
"context"
21+
2122
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta1"
23+
"sigs.k8s.io/cluster-api-provider-cloudstack/test/v1beta1/dummies"
2224

2325
. "github.com/onsi/ginkgo/v2"
2426
. "github.com/onsi/gomega"
25-
"sigs.k8s.io/cluster-api-provider-cloudstack/test/dummies"
2627
)
2728

2829
var _ = Describe("CloudStackMachine webhook", func() {

api/v1beta1/cloudstackmachinetemplate_webhook_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"context"
2121

2222
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta1"
23-
"sigs.k8s.io/cluster-api-provider-cloudstack/test/dummies"
23+
dummies "sigs.k8s.io/cluster-api-provider-cloudstack/test/dummies/v1beta1"
2424

2525
. "github.com/onsi/ginkgo/v2"
2626
. "github.com/onsi/gomega"

api/v1beta2/cloudstackmachinetemplate_webhook_test.go renamed to api/v1beta1/cloudstackmachinetemplate_webhook_test.go.bak

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package v1beta2_test
17+
package v1beta1_test
1818

1919
import (
2020
"context"
21+
2122
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta1"
23+
"sigs.k8s.io/cluster-api-provider-cloudstack/test/v1beta1/dummies"
2224

2325
. "github.com/onsi/ginkgo/v2"
2426
. "github.com/onsi/gomega"
25-
"sigs.k8s.io/cluster-api-provider-cloudstack/test/dummies"
2627
)
2728

2829
var _ = Describe("CloudStackMachineTemplate webhook", func() {

api/v1beta2/webhook_suite_test.go renamed to api/v1beta1/webhook_suite_test.go.bak

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package v1beta2_test
17+
package v1beta1_test
1818

1919
import (
2020
"context"
2121
"crypto/tls"
2222
"fmt"
23-
"k8s.io/client-go/rest"
2423
"net"
2524
"path/filepath"
2625
"testing"
2726
"time"
2827

28+
"k8s.io/client-go/rest"
29+
2930
. "github.com/onsi/ginkgo/v2"
3031
. "github.com/onsi/gomega"
3132

@@ -57,10 +58,10 @@ var _ = BeforeSuite(func() {
5758

5859
By("bootstrapping test environment")
5960
testEnv = &envtest.Environment{
60-
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
61+
CRDDirectoryPaths: []string{filepath.Join("../../", "config", "crd", "bases")},
6162
ErrorIfCRDPathMissing: false,
6263
WebhookInstallOptions: envtest.WebhookInstallOptions{
63-
Paths: []string{filepath.Join("..", "..", "config", "webhook")},
64+
Paths: []string{filepath.Join("../../", "config", "webhook")},
6465
},
6566
}
6667

0 commit comments

Comments
 (0)