Skip to content

Commit

Permalink
chore: update ut
Browse files Browse the repository at this point in the history
  • Loading branch information
sophon-zt committed Nov 18, 2024
1 parent 46049c9 commit cd36433
Show file tree
Hide file tree
Showing 14 changed files with 1,135 additions and 1,326 deletions.
176 changes: 88 additions & 88 deletions controllers/parameters/combine_upgrade_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,91 +19,91 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

package parameters

// import (
// "fmt"
//
// . "github.com/onsi/ginkgo/v2"
// . "github.com/onsi/gomega"
//
// parametersv1alpha1 "github.com/apecloud/kubeblocks/apis/parameters/v1alpha1"
// testutil "github.com/apecloud/kubeblocks/pkg/testutil/k8s"
// )
//
// var _ = Describe("Reconfigure CombineSyncPolicy", func() {
//
// var (
// k8sMockClient *testutil.K8sClientMockHelper
// )
//
// BeforeEach(func() {
// k8sMockClient = testutil.NewK8sMockClient()
// })
//
// AfterEach(func() {
// k8sMockClient.Finish()
// })
//
// Context("combine reconfigure policy test", func() {
// It("Should success without error", func() {
// By("check normal policy name")
// testPolicyExecs := &combineUpgradePolicy{
// policyExecutors: []reconfigurePolicy{&testPolicy{}},
// }
//
// Expect(upgradePolicyMap[parametersv1alpha1.DynamicReloadAndRestartPolicy]).ShouldNot(BeNil())
//
// mockParam := newMockReconfigureParams("simplePolicy", k8sMockClient.Client(),
// withMockInstanceSet(2, nil),
// withConfigSpec("for_test", map[string]string{
// "key": "value",
// }),
// withClusterComponent(2))
//
// Expect(testPolicyExecs.GetPolicyName()).Should(BeEquivalentTo(parametersv1alpha1.DynamicReloadAndRestartPolicy))
// status, err := testPolicyExecs.Upgrade(mockParam)
// Expect(err).Should(Succeed())
// Expect(status.Status).Should(BeEquivalentTo(ESNone))
// })
//
// It("Should success without error", func() {
// By("check failed policy name")
// testPolicyExecs := &combineUpgradePolicy{
// policyExecutors: []reconfigurePolicy{&testErrorPolicy{}},
// }
//
// mockParam := newMockReconfigureParams("simplePolicy", k8sMockClient.Client(),
// withMockInstanceSet(2, nil),
// withConfigSpec("for_test", map[string]string{
// "key": "value",
// }),
// withClusterComponent(2))
//
// Expect(testPolicyExecs.GetPolicyName()).Should(BeEquivalentTo(parametersv1alpha1.DynamicReloadAndRestartPolicy))
// status, err := testPolicyExecs.Upgrade(mockParam)
// Expect(err).ShouldNot(Succeed())
// Expect(status.Status).Should(BeEquivalentTo(ESFailedAndRetry))
// })
// })
// })
//
// type testPolicy struct {
// }
//
// type testErrorPolicy struct {
// }
//
// func (t testErrorPolicy) Upgrade(params reconfigureContext) (ReturnedStatus, error) {
// return makeReturnedStatus(ESFailedAndRetry), fmt.Errorf("testErrorPolicy failed")
// }
//
// func (t testErrorPolicy) GetPolicyName() string {
// return "testErrorPolicy"
// }
//
// func (t testPolicy) Upgrade(params reconfigureContext) (ReturnedStatus, error) {
// return makeReturnedStatus(ESNone), nil
// }
//
// func (t testPolicy) GetPolicyName() string {
// return "testPolicy"
// }
import (
"fmt"

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

parametersv1alpha1 "github.com/apecloud/kubeblocks/apis/parameters/v1alpha1"
testutil "github.com/apecloud/kubeblocks/pkg/testutil/k8s"
)

var _ = Describe("Reconfigure CombineSyncPolicy", func() {

var (
k8sMockClient *testutil.K8sClientMockHelper
)

BeforeEach(func() {
k8sMockClient = testutil.NewK8sMockClient()
})

AfterEach(func() {
k8sMockClient.Finish()
})

Context("combine reconfigure policy test", func() {
It("Should success without error", func() {
By("check normal policy name")
testPolicyExecs := &combineUpgradePolicy{
policyExecutors: []reconfigurePolicy{&testPolicy{}},
}

Expect(upgradePolicyMap[parametersv1alpha1.DynamicReloadAndRestartPolicy]).ShouldNot(BeNil())

mockParam := newMockReconfigureParams("simplePolicy", k8sMockClient.Client(),
withMockInstanceSet(2, nil),
withConfigSpec("for_test", map[string]string{
"key": "value",
}),
withClusterComponent(2))

Expect(testPolicyExecs.GetPolicyName()).Should(BeEquivalentTo(parametersv1alpha1.DynamicReloadAndRestartPolicy))
status, err := testPolicyExecs.Upgrade(mockParam)
Expect(err).Should(Succeed())
Expect(status.Status).Should(BeEquivalentTo(ESNone))
})

It("Should success without error", func() {
By("check failed policy name")
testPolicyExecs := &combineUpgradePolicy{
policyExecutors: []reconfigurePolicy{&testErrorPolicy{}},
}

mockParam := newMockReconfigureParams("simplePolicy", k8sMockClient.Client(),
withMockInstanceSet(2, nil),
withConfigSpec("for_test", map[string]string{
"key": "value",
}),
withClusterComponent(2))

Expect(testPolicyExecs.GetPolicyName()).Should(BeEquivalentTo(parametersv1alpha1.DynamicReloadAndRestartPolicy))
status, err := testPolicyExecs.Upgrade(mockParam)
Expect(err).ShouldNot(Succeed())
Expect(status.Status).Should(BeEquivalentTo(ESFailedAndRetry))
})
})
})

type testPolicy struct {
}

type testErrorPolicy struct {
}

func (t testErrorPolicy) Upgrade(params reconfigureContext) (ReturnedStatus, error) {
return makeReturnedStatus(ESFailedAndRetry), fmt.Errorf("testErrorPolicy failed")
}

func (t testErrorPolicy) GetPolicyName() string {
return "testErrorPolicy"
}

func (t testPolicy) Upgrade(params reconfigureContext) (ReturnedStatus, error) {
return makeReturnedStatus(ESNone), nil
}

func (t testPolicy) GetPolicyName() string {
return "testPolicy"
}
2 changes: 1 addition & 1 deletion controllers/parameters/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,6 @@ func cleanEnv() {
testapps.ClearResourcesWithRemoveFinalizerOption(&testCtx, generics.SecretSignature, true, inNS)
testapps.ClearResourcesWithRemoveFinalizerOption(&testCtx, generics.InstanceSetSignature, true, inNS, ml)
testapps.ClearResourcesWithRemoveFinalizerOption(&testCtx, generics.ConfigurationSignature, false, inNS, ml)
testapps.ClearResourcesWithRemoveFinalizerOption(&testCtx, generics.ComponentParameterSignature, true, inNS, ml)
testapps.ClearResourcesWithRemoveFinalizerOption(&testCtx, generics.ComponentParameterSignature, true, inNS)
testapps.ClearResourcesWithRemoveFinalizerOption(&testCtx, generics.ParameterSignature, true, inNS, ml)
}
Loading

0 comments on commit cd36433

Please sign in to comment.