This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/shardingsphere-on-cloud.git


The following commit(s) were added to refs/heads/main by this push:
     new 8a0a619  chore(reconcile): add unit test for ToYaml
     new 2d91cc1  Merge pull request #104 from 
amarps/reconcile_unit_test_to_yaml
8a0a619 is described below

commit 8a0a6194e5a7778f4bcb4e92a4fa65932512610f
Author: senjaya <[email protected]>
AuthorDate: Wed Oct 26 19:35:16 2022 +0700

    chore(reconcile): add unit test for ToYaml
---
 .../pkg/reconcile/reconcile_test.go                | 90 ++++++++++++++++++++++
 1 file changed, 90 insertions(+)

diff --git a/shardingsphere-operator/pkg/reconcile/reconcile_test.go 
b/shardingsphere-operator/pkg/reconcile/reconcile_test.go
index 0f066f9..d4f35ac 100644
--- a/shardingsphere-operator/pkg/reconcile/reconcile_test.go
+++ b/shardingsphere-operator/pkg/reconcile/reconcile_test.go
@@ -480,7 +480,97 @@ func Test_ConstructHPA(t *testing.T) {
 }
 
 func Test_ToYAML(t *testing.T) {
+       cases := []struct {
+               proxyCfg *v1alpha1.ShardingSphereProxyServerConfig
+               exp      string
+               message  string
+       }{
+               {
+                       proxyCfg: &v1alpha1.ShardingSphereProxyServerConfig{},
+                       exp: `mode:
+  type: ""
+  repository:
+    type: ""
+    props:
+      namespace: ""
+      server-lists: ""
+authority:
+  users: []
+  privilege: null
+`,
+                       message: "Empty proxy server config should generate 
yaml with empty value",
+               },
+               {
+                       proxyCfg: &v1alpha1.ShardingSphereProxyServerConfig{
+                               Spec: v1alpha1.ProxyConfigSpec{
+                                       ClusterConfig: v1alpha1.ClusterConfig{
+                                               Type: "Cluster",
+                                               Repository: 
v1alpha1.RepositoryConfig{
+                                                       Type: "Zookeeper",
+                                                       Props: 
v1alpha1.ClusterProps{
+                                                               Namespace:      
              "cluster-sharding-mode",
+                                                               ServerLists:    
              "host1:2181,host2:2181",
+                                                               
RetryIntervalMilliseconds:    500,
+                                                               MaxRetries:     
              3,
+                                                               
TimeToLiveSeconds:            60,
+                                                               
OperationTimeoutMilliseconds: 500,
+                                                       },
+                                               },
+                                       },
+                                       Authority: v1alpha1.Auth{
+                                               Users: []v1alpha1.User{
+                                                       {
+                                                               User:     
"John",
+                                                               Password: 
"123456",
+                                                       },
+                                               },
+                                               Privilege: &v1alpha1.Privilege{
+                                                       Type: "Admin",
+                                               },
+                                       },
+                                       Props: &v1alpha1.Props{
+                                               KernelExecutorSize:             
   16,
+                                               CheckTableMetadataEnabled:      
   false,
+                                               ProxyBackendQueryFetchSize:     
   -1,
+                                               CheckDuplicateTableEnabled:     
   false,
+                                               ProxyFrontendExecutorSize:      
   0,
+                                               ProxyBackendExecutorSuitable:   
   "OLAP",
+                                               ProxyBackendDriverType:         
   "JDBC",
+                                               
ProxyFrontendDatabaseProtocolType: "",
+                                       },
+                               },
+                       },
+                       exp: `mode:
+  type: Cluster
+  repository:
+    type: Zookeeper
+    props:
+      namespace: cluster-sharding-mode
+      server-lists: host1:2181,host2:2181
+      retryIntervalMilliseconds: 500
+      maxRetries: 3
+      timeToLiveSeconds: 60
+      operationTimeoutMilliseconds: 500
+authority:
+  users:
+  - user: John
+    password: "123456"
+  privilege:
+    type: Admin
+props:
+  kernel-executor-size: 16
+  proxy-backend-query-fetch-size: -1
+  proxy-backend-executor-suitable: OLAP
+  proxy-backend-driver-type: JDBC
+`,
+                       message: "Should generate yaml with the same value as 
ShardingSphereProxyServerConfig.Spec",
+               },
+       }
 
+       for _, c := range cases {
+               act := toYaml(c.proxyCfg)
+               assert.Equal(t, c.exp, act, c.message)
+       }
 }
 
 func Test_UpdateDeployment(t *testing.T) {

Reply via email to