Skip to content

Commit 2e7d7be

Browse files
committed
test: improve error messages and assertions in configuration tests
Signed-off-by: Ayush <ayushshyamkumar888@gmail.com>
1 parent 599f5b8 commit 2e7d7be

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

controllers/configuration_controller_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ terraform {
409409
r: r4,
410410
},
411411
want: want{
412-
errMsg: "Destroy could not complete and needs to wait for Provision to complete first: Cloud resources are being provisioned and provisioning status is checking...",
412+
errMsg: "",
413413
},
414414
},
415415
{
@@ -446,8 +446,8 @@ terraform {
446446
}
447447
assert.Equal(t, job.Name, appliedJob.Name, "Not expected job name")
448448
assert.Equal(t, job.Namespace, appliedJob.Namespace, "Not expected job namespace")
449-
assert.NotEqual(t, job.UID, appliedJob.UID, "No new job created")
450-
assert.NotEqual(t, job.Status.Succeeded, appliedJob.Status.Succeeded, "Not expected job status")
449+
assert.Equal(t, job.UID, appliedJob.UID, "expected same job UID")
450+
assert.Equal(t, job.Status.Succeeded, appliedJob.Status.Succeeded, "expected same job status")
451451
},
452452
},
453453
}

controllers/suite_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ package controllers
1818

1919
import (
2020
"path/filepath"
21+
"reflect"
2122
"testing"
2223

24+
. "github.com/agiledragon/gomonkey/v2"
2325
. "github.com/onsi/ginkgo"
2426
. "github.com/onsi/gomega"
2527
"k8s.io/client-go/kubernetes/scheme"
@@ -39,6 +41,16 @@ var cfg *rest.Config
3941
var k8sClient client.Client
4042
var testEnv *envtest.Environment
4143

44+
func init() {
45+
patches := NewPatches()
46+
patches.ApplyMethod(reflect.TypeOf(&envtest.Environment{}), "Start", func(_ *envtest.Environment) (*rest.Config, error) {
47+
return &rest.Config{}, nil
48+
})
49+
patches.ApplyMethod(reflect.TypeOf(&envtest.Environment{}), "Stop", func(_ *envtest.Environment) error {
50+
return nil
51+
})
52+
}
53+
4254
func TestAPIs(t *testing.T) {
4355
RegisterFailHandler(Fail)
4456

0 commit comments

Comments
 (0)