refactor: [cmd-test] add test for cmd

上级 ec8ec0f3
......@@ -10,7 +10,6 @@ import (
"github.com/phodal/coca/core/domain"
"github.com/spf13/cobra"
"log"
"os"
"regexp"
"strconv"
"strings"
......@@ -73,7 +72,7 @@ var apiCmd = &cobra.Command{
}
if apiCmdConfig.ShowCount {
table := tablewriter.NewWriter(os.Stdout)
table := tablewriter.NewWriter(output)
table.SetHeader([]string{"Size", "Method", "Uri", "Caller"})
......
......@@ -19,7 +19,7 @@ func TestApi(t *testing.T) {
tests := []cmdTestCase{{
name: "api",
cmd: "api -c -f -p " + abs,
golden: "",
golden: "testdata/api.txt",
}}
runTestCmd(t, tests)
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ import (
"github.com/mattn/go-shellwords"
"github.com/spf13/cobra"
"os"
"path/filepath"
"strings"
"testing"
)
......@@ -29,7 +30,8 @@ func runTestCmd(t *testing.T, tests []cmdTestCase) {
t.Errorf("expected error, got '%v'", err)
}
if tt.golden != "" {
AssertGoldenString(t, output, tt.golden)
slash := filepath.FromSlash(tt.golden)
AssertGoldenString(t, output, slash)
}
})
}
......
......@@ -10,7 +10,6 @@ import (
"github.com/phodal/coca/core/infrastructure/string_helper"
"github.com/spf13/cobra"
"log"
"os"
"strconv"
)
......@@ -50,7 +49,7 @@ var countCmd = &cobra.Command{
callMapSort = callMapSort[:countCmdConfig.Top]
}
table := tablewriter.NewWriter(os.Stdout)
table := tablewriter.NewWriter(output)
table.SetHeader([]string{"Refs Count", "method"})
for _, count := range callMapSort {
......
......@@ -19,7 +19,7 @@ func TestCount(t *testing.T) {
tests := []cmdTestCase{{
name: "count",
cmd: "count -t 1",
golden: "testdata/count.txt",
golden: filepath.FromSlash("testdata/count.txt"),
}}
runTestCmd(t, tests)
}
......@@ -10,7 +10,6 @@ import (
"github.com/phodal/coca/core/domain"
"github.com/spf13/cobra"
"log"
"os"
"strconv"
)
......@@ -46,7 +45,7 @@ var evaluateCmd = &cobra.Command{
cModel, _ := json.MarshalIndent(result, "", "\t")
cmd_util.WriteToCocaFile("evaluate.json", string(cModel))
table := tablewriter.NewWriter(os.Stdout)
table := tablewriter.NewWriter(output)
table.SetHeader([]string{"Type", "Count", "Level", "Total", "Rate"})
classCount := result.Summary.ClassCount
......
......@@ -19,7 +19,7 @@ func TestEvaluate(t *testing.T) {
tests := []cmdTestCase{{
name: "evaluate",
cmd: "evaluate",
golden: "",
golden: "testdata/evaluate.txt",
}}
runTestCmd(t, tests)
}
\ No newline at end of file
+------+--------+-------------+-----------------------------------------------------+
| SIZE | METHOD | URI | CALLER |
+------+--------+-------------+-----------------------------------------------------+
| 2 | POST | /books | com.phodal.pholedge.book.BookController.createBook |
| 2 | PUT | /books/{id} | com.phodal.pholedge.book.BookController.updateBook |
| 2 | GET | /books/ | com.phodal.pholedge.book.BookController.getBookList |
| 2 | GET | /books/{id} | com.phodal.pholedge.book.BookController.getBookById |
+------+--------+-------------+-----------------------------------------------------+
+------------+--------------------------------------+
| REFS COUNT | METHOD |
+------------+--------------------------------------+
| 1 | repositories.AggregateRootARepo.save |
+------------+--------------------------------------+
+--------------------------------+-------+-----------------------+-------+----------+
| TYPE | COUNT | LEVEL | TOTAL | RATE |
+--------------------------------+-------+-----------------------+-------+----------+
| Nullable / Return Null | 0 | Method | 6 | 0.00% |
| Utils | 0 | Class | 14 | 0.00% |
| Static Method | 1 | Method | 6 | 0.00% |
| Average Method Num. | 6 | Method/Class | 14 | 0.428571 |
| Method Num. Std Dev / 标准差 | 6 | Class | - | 0.646206 |
| Average Method Length | 0 | Without Getter/Setter | 0 | NaN |
| Method Length Std Dev / 标准差 | 6 | Method | - | NaN |
+--------------------------------+-------+-----------------------+-------+----------+
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册