github.com/easysoft/zendata@v0.0.0-20240513203326-705bd5a7fd67/cmd/test/command/cmd_gen_output_test.go (about) 1 package main 2 3 import ( 4 "testing" 5 6 "github.com/easysoft/zendata/cmd/test/consts" 7 "github.com/easysoft/zendata/cmd/test/gen" 8 testHelper "github.com/easysoft/zendata/cmd/test/helper" 9 "github.com/ozontech/allure-go/pkg/framework/provider" 10 "github.com/ozontech/allure-go/pkg/framework/suite" 11 ) 12 13 func TestGenerateOutputCmd(t *testing.T) { 14 suite.RunSuite(t, new(GenerateOutputCmdSuite)) 15 } 16 17 type GenerateOutputCmdSuite struct { 18 suite.Suite 19 } 20 21 func (s *GenerateOutputCmdSuite) BeforeAll(t provider.T) { 22 testHelper.BeforeAll() 23 t.AddSubSuite("GenerateOutputCmd") 24 } 25 func (s *GenerateOutputCmdSuite) BeforeEach(t provider.T) { 26 testHelper.PreCase() 27 t.AddSubSuite("GenerateOutputCmd") 28 } 29 func (s *GenerateOutputCmdSuite) AfterEach(t provider.T) { 30 testHelper.PostCase() 31 } 32 33 func (s *GenerateOutputCmdSuite) TestGenerateText(t provider.T) { 34 t.ID("0") 35 36 out := gen.New(). 37 SetConfigs([]string{consts.CommandTestFile}). 38 SetFields("f1,f2"). 39 SetOutput("test/out/result.txt"). 40 Gen() 41 42 t.Require().Contains(out, "[1]\t123\t\n", "check generated data") 43 } 44 45 func (s *GenerateOutputCmdSuite) TestGenerateJson(t provider.T) { 46 t.ID("0") 47 48 out := gen.New(). 49 SetConfigs([]string{consts.CommandTestFile}). 50 SetFields("f1,f2"). 51 SetOutput("test/out/result.json"). 52 SetTrim(true). 53 Gen() 54 55 t.Require().Contains(out, `"f2": "123"`, "check generated data") 56 } 57 58 func (s *GenerateOutputCmdSuite) TestGenerateXml(t provider.T) { 59 t.ID("0") 60 61 out := gen.New(). 62 SetConfigs([]string{consts.CommandTestFile}). 63 SetFields("f1,f2"). 64 SetOutput("test/out/result.xml"). 65 SetTrim(true). 66 Gen() 67 68 t.Require().Contains(out, "<f1>1</f1>", "check generated data") 69 } 70 71 func (s *GenerateOutputCmdSuite) TestGenerateSql(t provider.T) { 72 t.ID("0") 73 74 out := gen.New(). 75 SetConfigs([]string{consts.CommandTestFile}). 76 SetFields("f1,f2"). 77 SetDBTable("mysql"). 78 SetTable("user"). 79 SetOutput("test/out/result.sql"). 80 SetTrim(true). 81 Gen() 82 83 t.Require().Contains(out, "('1','123')", "check generated data") 84 } 85 86 func (s *GenerateOutputCmdSuite) TestGenerateCsv(t provider.T) { 87 t.ID("0") 88 89 out := gen.New(). 90 SetConfigs([]string{consts.CommandTestFile}). 91 SetFields("f1,f2"). 92 SetOutput("test/out/result.csv"). 93 SetTrim(true). 94 Gen() 95 96 t.Require().Contains(out, "1,123\n", "check generated data") 97 } 98 99 func (s *GenerateOutputCmdSuite) TestGenerateExcel(t provider.T) { 100 t.ID("0") 101 102 pth := "test/out/result.xlsx" 103 104 gen.New(). 105 SetConfigs([]string{consts.CommandTestFile}). 106 SetFields("f1,f2"). 107 SetOutput(pth). 108 SetTrim(true). 109 Gen() 110 111 value := testHelper.GetExcelData(pth, 0, 1, 1) 112 113 t.Require().Contains(value, "123", "check generated data") 114 } 115 116 func (s *GenerateOutputCmdSuite) TestGenerateProtobuf(t provider.T) { 117 t.ID("0") 118 119 out := gen.New(). 120 SetConfigs([]string{consts.CommandTestFileProto}). 121 SetProtoCls("Person"). 122 Gen() 123 124 t.Require().Contains(out, "class Person", "check generated data") 125 }