Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test for config edit #96

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified pkg/cluster/charts/apecloud-mysql-cluster.tgz
Binary file not shown.
Binary file modified pkg/cluster/charts/kafka-cluster.tgz
Binary file not shown.
Binary file modified pkg/cluster/charts/llm-cluster.tgz
Binary file not shown.
Binary file modified pkg/cluster/charts/mongodb-cluster.tgz
Binary file not shown.
Binary file modified pkg/cluster/charts/postgresql-cluster.tgz
Binary file not shown.
Binary file modified pkg/cluster/charts/redis-cluster.tgz
Binary file not shown.
Binary file modified pkg/cluster/charts/xinference-cluster.tgz
Binary file not shown.
58 changes: 58 additions & 0 deletions pkg/cmd/cluster/config_edit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package cluster

import (
"github.com/apecloud/kbcli/pkg/action"
"github.com/apecloud/kbcli/pkg/types"
appsv1alpha1 "github.com/apecloud/kubeblocks/apis/apps/v1alpha1"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/cli-runtime/pkg/genericiooptions"
dynamicfakeclient "k8s.io/client-go/dynamic/fake"
"k8s.io/client-go/kubernetes/scheme"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
)

func NewConfigEditTest(ns, cName string, opsType appsv1alpha1.OpsType, objs ...runtime.Object) (*cmdtesting.TestFactory, *action.CreateOptions) {
streams, _, _, _ := genericiooptions.NewTestIOStreams()
tf := cmdtesting.NewTestFactory().WithNamespace(ns)
var editConfigOps = editConfigOptions{
configOpsOptions: configOpsOptions{
ComponentName: "mysql",
Parameters: []string{"config-spec"},
},
enableDelete: false,
}
baseOptions := &action.CreateOptions{
IOStreams: streams,
Name: cName,
Namespace: ns,
}

err := appsv1alpha1.AddToScheme(scheme.Scheme)
if err != nil {
panic(err)
}

// TODO using config-spec and component to test the program
ParamsMapping := map[schema.GroupVersionResource]string{
types.ClusterDefGVR(): types.KindClusterDef + "List",
types.ClusterVersionGVR(): types.KindClusterVersion + "List",
types.ClusterGVR(): types.KindCluster + "List",
types.ConfigConstraintGVR(): types.KindConfigConstraint + "List",
types.BackupGVR(): types.KindBackup + "List",
types.RestoreGVR(): types.KindRestore + "List",
types.OpsGVR(): types.KindOps + "List",
}
baseOptions.Dynamic = dynamicfakeclient.NewSimpleDynamicClientWithCustomListKinds(scheme.Scheme, ParamsMapping, objs...)
editConfigOptions.Run(editConfigOps, func() error {
if opsType == appsv1alpha1.ReasonOpsRequestFailed {
return errors.New("OpsRequestFailed")
} else if opsType == appsv1alpha1.ClusterDefinitionKind {
return errors.New("ClusterDefinitionKind")
} else {
return nil
}
})
return tf, baseOptions
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where used this function?