Skip to content

Commit

Permalink
refactor(merge): merge 3.1 code
Browse files Browse the repository at this point in the history
merge 3.1 code

Signed-off-by: ysicing <[email protected]>
  • Loading branch information
ysicing committed Dec 4, 2023
2 parents ccb840b + 8c0dbc2 commit a584d38
Show file tree
Hide file tree
Showing 239 changed files with 3,112 additions and 1,669 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@

/zendata
client/yarn-error.log
**/allure-results/
/test/unittest/out/
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.1
3.1
21 changes: 21 additions & 0 deletions cmd/command/action/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package action

import (
"github.com/easysoft/zendata/internal/command"
logUtils "github.com/easysoft/zendata/pkg/utils/log"
)

func GenData(files []string) {
command.PrintStartInfo()

err := command.SetOutFormat()
defer logUtils.OutputFileWriter.Close()
if err != nil {
return
}

mainCtrl, _ := command.InitCtrl()
mainCtrl.Generate(files)

command.PrintEndInfo()
}
8 changes: 8 additions & 0 deletions cmd/command/action/parse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package action

import "github.com/easysoft/zendata/internal/command"

func GenYaml(input string) {
mainCtrl, _ := command.InitCtrl()
mainCtrl.GenYaml(input)
}
35 changes: 8 additions & 27 deletions cmd/command/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"syscall"

"github.com/easysoft/zendata/cmd/command/action"
"github.com/easysoft/zendata/internal/command"
commandConfig "github.com/easysoft/zendata/internal/command/config"
configUtils "github.com/easysoft/zendata/internal/pkg/config"
Expand Down Expand Up @@ -134,10 +135,10 @@ func main() {

flagSet.Parse(os.Args[1:])

execCommand()
ExecCommand()
}

func execCommand() {
func ExecCommand() {
if len(os.Args) == 1 {
os.Args = append(os.Args, "-help")
}
Expand Down Expand Up @@ -169,12 +170,12 @@ func opts(files []string) {
logUtils.PrintVersion(AppVersion, BuildTime, GoVersion, GitHash)
return

} else if example {
logUtils.PrintExample()
return
} else if help {
logUtils.PrintUsage()
return
} else if example {
logUtils.PrintExample()
return
} else if set {
helper.Set()
return
Expand All @@ -191,7 +192,7 @@ func opts(files []string) {
helper.AddMd5(md5, salt)
return
} else if parse {
genYaml(input)
action.GenYaml(input)
return
} else if mock {
if input == "" {
Expand All @@ -202,34 +203,14 @@ func opts(files []string) {
return
}

genData(files)
}

func genYaml(input string) {
mainCtrl, _ := command.InitCtrl()
mainCtrl.GenYaml(input)
action.GenData(files)
}

func genMock(input string) {
mainCtrl, _ := command.InitCtrl()
mainCtrl.GenMock(input)
}

func genData(files []string) {
command.PrintStartInfo()

err := command.SetOutFormat()
defer logUtils.OutputFileWriter.Close()
if err != nil {
return
}

mainCtrl, _ := command.InitCtrl()
mainCtrl.Generate(files)

command.PrintEndInfo()
}

func init() {
cleanup()
}
Expand Down
52 changes: 52 additions & 0 deletions cmd/test/command/cmd_data_list_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package main

import (
"testing"

"github.com/easysoft/zendata/cmd/test/consts"
testHelper "github.com/easysoft/zendata/cmd/test/helper"
"github.com/easysoft/zendata/internal/pkg/helper"
"github.com/ozontech/allure-go/pkg/framework/provider"
"github.com/ozontech/allure-go/pkg/framework/suite"
)

func TestDataListCmd(t *testing.T) {
suite.RunSuite(t, new(DataListCmdSuite))
}

type DataListCmdSuite struct {
suite.Suite
}

func (s *DataListCmdSuite) BeforeAll(t provider.T) {
testHelper.BeforeAll()
t.AddSubSuite("DataListCmd")
}
func (s *DataListCmdSuite) BeforeEach(t provider.T) {
testHelper.PreCase()

t.AddSubSuite("DataListCmd")
}
func (s *DataListCmdSuite) AfterEach(t provider.T) {
testHelper.PostCase()
}

func (s *DataListCmdSuite) TestDataList(t provider.T) {
t.ID("0")

helper.ListData()

out := consts.Buf.String()

t.Require().Contains(out, "test.v1.yaml", "check list content")
}

func (s *DataListCmdSuite) TestResList(t provider.T) {
t.ID("0")

helper.ListRes()

out := consts.Buf.String()

t.Require().Contains(out, "city.v1.xlsx", "check list content")
}
55 changes: 55 additions & 0 deletions cmd/test/command/cmd_data_view_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package main

import (
"testing"

"github.com/easysoft/zendata/cmd/test/consts"
testHelper "github.com/easysoft/zendata/cmd/test/helper"
"github.com/easysoft/zendata/internal/pkg/helper"
"github.com/ozontech/allure-go/pkg/framework/provider"
"github.com/ozontech/allure-go/pkg/framework/suite"
)

func TestDataViewCmd(t *testing.T) {
suite.RunSuite(t, new(DataViewCmdSuite))
}

type DataViewCmdSuite struct {
suite.Suite
}

func (s *DataViewCmdSuite) BeforeAll(t provider.T) {
testHelper.BeforeAll()
t.AddSubSuite("DataListCmd")
}
func (s *DataViewCmdSuite) BeforeEach(t provider.T) {
testHelper.PreCase()
t.AddSubSuite("DataViewCmd")
}
func (s *DataViewCmdSuite) AfterEach(t provider.T) {
testHelper.PostCase()
}

func (s *DataViewCmdSuite) TestViewDataBuildinExcel(t provider.T) {
t.ID("0")

consts.Buf.Reset()
helper.View("city.v1.city")
out := consts.Buf.String()
t.Require().Contains(out, "北京市", "check excel content")
}

func (s *DataViewCmdSuite) TestViewDataBuildinConfig(t provider.T) {
t.ID("0")

consts.Buf.Reset()
helper.View("color/v1.yaml")
out := consts.Buf.String()
t.Require().Contains(out, "rgb", "check excel content")

consts.Buf.Reset()
helper.View("color.v1.yaml")
out = consts.Buf.String()

t.Require().Contains(out, "rgb", "check excel content")
}
42 changes: 42 additions & 0 deletions cmd/test/command/cmd_gen_article_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"testing"

"github.com/easysoft/zendata/cmd/test/consts"
"github.com/easysoft/zendata/cmd/test/gen"
testHelper "github.com/easysoft/zendata/cmd/test/helper"
"github.com/ozontech/allure-go/pkg/framework/provider"
"github.com/ozontech/allure-go/pkg/framework/suite"
)

func TestGenerateArticleCmd(t *testing.T) {
suite.RunSuite(t, new(GenerateArticleCmdSuite))
}

type GenerateArticleCmdSuite struct {
suite.Suite
}

func (s *GenerateArticleCmdSuite) BeforeAll(t provider.T) {
testHelper.BeforeAll()
t.AddSubSuite("GenerateArticleCmd")
}
func (s *GenerateArticleCmdSuite) BeforeEach(t provider.T) {
testHelper.PreCase()
t.AddSubSuite("GenerateArticleCmd")
}
func (s *GenerateArticleCmdSuite) AfterEach(t provider.T) {
testHelper.PostCase()
}

func (s *GenerateArticleCmdSuite) TestGenerateArticle(t provider.T) {
t.ID("0")

out := gen.New().
SetConfigs([]string{consts.CommandTestFileArticleConfig}).
SetOutput(consts.CommandTestFileArticleOut).
Gen()

t.Require().NotContains(out, "{人称代词}", "check generated data")
}
Loading

0 comments on commit a584d38

Please sign in to comment.