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

zhongxjian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-kubernetes.git


The following commit(s) were added to refs/heads/master by this push:
     new 5f8aea9a [dubboctl] fix test error v2
5f8aea9a is described below

commit 5f8aea9a694764a93e674edbaa298cd322d41feb
Author: mfordjody <[email protected]>
AuthorDate: Wed Oct 30 11:47:56 2024 +0800

    [dubboctl] fix test error v2
---
 dubboctl/{pkg/manifest => cmd}/manifest_test.go | 74 +++++++++++++------------
 dubboctl/{pkg/profile => cmd}/profile_test.go   | 60 ++++++++++----------
 2 files changed, 69 insertions(+), 65 deletions(-)

diff --git a/dubboctl/pkg/manifest/manifest_test.go 
b/dubboctl/cmd/manifest_test.go
similarity index 80%
rename from dubboctl/pkg/manifest/manifest_test.go
rename to dubboctl/cmd/manifest_test.go
index 16d873f4..64cdafa4 100644
--- a/dubboctl/pkg/manifest/manifest_test.go
+++ b/dubboctl/cmd/manifest_test.go
@@ -13,10 +13,12 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package manifest
+package cmd
 
 import (
+       "bytes"
        "os"
+       "strings"
        "testing"
 )
 
@@ -74,7 +76,7 @@ func TestManifestGenerate(t *testing.T) {
        }
        for _, test := range tests {
                t.Run(test.desc, func(t *testing.T) {
-                       testExecute(t, test.cmd, test.wantErr)
+                       testManifestExecute(t, test.cmd, test.wantErr)
                        // remove temporary dir
                        if test.temp != "" {
                                os.RemoveAll(test.temp)
@@ -100,7 +102,7 @@ func TestManifestInstall(t *testing.T) {
 
        for _, test := range tests {
                t.Run(test.desc, func(t *testing.T) {
-                       testExecute(t, test.cmd, test.wantErr)
+                       testManifestExecute(t, test.cmd, test.wantErr)
                })
        }
 }
@@ -126,8 +128,8 @@ func TestManifestUninstall(t *testing.T) {
        for _, test := range tests {
                t.Run(test.desc, func(t *testing.T) {
                        // prepare existing resources
-                       testExecute(t, test.before, false)
-                       testExecute(t, test.cmd, test.wantErr)
+                       testManifestExecute(t, test.before, false)
+                       testManifestExecute(t, test.cmd, test.wantErr)
                })
        }
 }
@@ -153,36 +155,36 @@ func TestManifestDiff(t *testing.T) {
                        },
                },
        }
-       //for _, test := range tests {
-       //      t.Run(test.desc, func(t *testing.T) {
-       //              for _, before := range test.befores {
-       //                      testExecute(t, before, false)
-       //              }
-       //              testExecute(t, test.cmd, test.wantErr)
-       //              for _, temp := range test.temps {
-       //                      if temp != "" {
-       //                              os.RemoveAll(temp)
-       //                      }
-       //              }
-       //      })
-       //}
+       for _, test := range tests {
+               t.Run(test.desc, func(t *testing.T) {
+                       for _, before := range test.befores {
+                               testManifestExecute(t, before, false)
+                       }
+                       testManifestExecute(t, test.cmd, test.wantErr)
+                       for _, temp := range test.temps {
+                               if temp != "" {
+                                       os.RemoveAll(temp)
+                               }
+                       }
+               })
+       }
 }
 
-//func testExecute(t *testing.T, cmds string, wantErr bool) string {
-//     var out bytes.Buffer
-//     args := strings.Split(cmds, " ")
-//     rootCmd := cmd.GetRootCmd(args)
-//     rootCmd.SetOut(&out)
-//     if err := rootCmd.Execute(); err != nil {
-//             if wantErr {
-//                     return ""
-//             }
-//             t.Errorf("execute %s failed, err: %s", cmds, err)
-//             return ""
-//     }
-//     if wantErr {
-//             t.Errorf("want err but got no err")
-//             return ""
-//     }
-//     return out.String()
-//}
+func testManifestExecute(t *testing.T, cmds string, wantErr bool) string {
+       var out bytes.Buffer
+       args := strings.Split(cmds, " ")
+       rootCmd := GetRootCmd(args)
+       rootCmd.SetOut(&out)
+       if err := rootCmd.Execute(); err != nil {
+               if wantErr {
+                       return ""
+               }
+               t.Errorf("execute %s failed, err: %s", cmds, err)
+               return ""
+       }
+       if wantErr {
+               t.Errorf("want err but got no err")
+               return ""
+       }
+       return out.String()
+}
diff --git a/dubboctl/pkg/profile/profile_test.go b/dubboctl/cmd/profile_test.go
similarity index 79%
rename from dubboctl/pkg/profile/profile_test.go
rename to dubboctl/cmd/profile_test.go
index 53361d12..00057d10 100644
--- a/dubboctl/pkg/profile/profile_test.go
+++ b/dubboctl/cmd/profile_test.go
@@ -13,9 +13,11 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package profile
+package cmd
 
 import (
+       "bytes"
+       "strings"
        "testing"
 )
 
@@ -67,7 +69,7 @@ func TestProfileList(t *testing.T) {
 
        for _, test := range tests {
                t.Run(test.desc, func(t *testing.T) {
-                       res := testExecute(t, test.cmd, test.wantErr)
+                       res := testProfileExecute(t, test.cmd, test.wantErr)
                        if test.want != "" && test.want != res {
                                t.Errorf("want:\n%s\nbutgot:\n%s\n", test.want, 
res)
                                return
@@ -118,32 +120,32 @@ func TestProfileDiff(t *testing.T) {
                },
        }
 
-       //for _, test := range tests {
-       //      t.Run(test.desc, func(t *testing.T) {
-       //              res := testExecute(t, test.cmd, test.wantErr)
-       //              if test.want != "" && test.want != res {
-       //                      t.Errorf("want:\n%s\nbutgot:\n%s\n", test.want, 
res)
-       //                      return
-       //              }
-       //      })
-       //}
+       for _, test := range tests {
+               t.Run(test.desc, func(t *testing.T) {
+                       res := testProfileExecute(t, test.cmd, test.wantErr)
+                       if test.want != "" && test.want != res {
+                               t.Errorf("want:\n%s\nbutgot:\n%s\n", test.want, 
res)
+                               return
+                       }
+               })
+       }
 }
 
-//func testExecute(t *testing.T, cmds string, wantErr bool) string {
-//     var out bytes.Buffer
-//     args := strings.Split(cmds, " ")
-//     rootCmd := cmd.GetRootCmd(args)
-//     rootCmd.SetOut(&out)
-//     if err := rootCmd.Execute(); err != nil {
-//             if wantErr {
-//                     return ""
-//             }
-//             t.Errorf("execute %s failed, err: %s", cmds, err)
-//             return ""
-//     }
-//     if wantErr {
-//             t.Errorf("want err but got no err")
-//             return ""
-//     }
-//     return out.String()
-//}
+func testProfileExecute(t *testing.T, cmds string, wantErr bool) string {
+       var out bytes.Buffer
+       args := strings.Split(cmds, " ")
+       rootCmd := GetRootCmd(args)
+       rootCmd.SetOut(&out)
+       if err := rootCmd.Execute(); err != nil {
+               if wantErr {
+                       return ""
+               }
+               t.Errorf("execute %s failed, err: %s", cmds, err)
+               return ""
+       }
+       if wantErr {
+               t.Errorf("want err but got no err")
+               return ""
+       }
+       return out.String()
+}

Reply via email to