cli_view_test.go 1.5 KB
Newer Older
aaronchen2k2k's avatar
aaronchen2k2k 已提交
1 2 3 4 5 6 7 8
package main

import (
	"fmt"
	"regexp"
	"testing"
	"time"

aaronchen2k2k's avatar
aaronchen2k2k 已提交
9 10
	commonTestHelper "github.com/easysoft/zentaoatf/cmd/test/helper/common"
	constTestHelper "github.com/easysoft/zentaoatf/cmd/test/helper/conf"
aaronchen2k2k's avatar
aaronchen2k2k 已提交
11 12 13 14 15 16 17 18 19 20 21
	expect "github.com/easysoft/zentaoatf/pkg/lib/expect"
	"github.com/ozontech/allure-go/pkg/framework/provider"
	"github.com/ozontech/allure-go/pkg/framework/suite"
)

type ViewSuite struct {
	suite.Suite
}

func (s *ViewSuite) BeforeEach(t provider.T) {
	t.ID("1593")
Z
zhaoke 已提交
22
	commonTestHelper.ReplaceLabel(t, "命令行-查看脚本详情")
aaronchen2k2k's avatar
aaronchen2k2k 已提交
23 24
}
func (s *ViewSuite) TestViewSuite(t provider.T) {
Z
zhaoke 已提交
25
	t.Require().Equal("Success", testView(commonTestHelper.GetZtfPath()+fmt.Sprintf(" view %scmd/test/demo/1_string_match_fail.php", constTestHelper.RootPath), regexp.MustCompile("check string matches pattern")))
aaronchen2k2k's avatar
aaronchen2k2k 已提交
26

Z
zhaoke 已提交
27
	t.Require().Equal("Success", testView(commonTestHelper.GetZtfPath()+fmt.Sprintf(" -v %scmd/test/demo -k 1", constTestHelper.RootPath), regexp.MustCompile("check string matches pattern")))
aaronchen2k2k's avatar
aaronchen2k2k 已提交
28

Z
zhaoke 已提交
29
	t.Require().Equal("Success", testView(commonTestHelper.GetZtfPath()+fmt.Sprintf(" view %scmd/test/demo -k match", constTestHelper.RootPath), regexp.MustCompile("Found 5 test cases|发现5个用例")))
aaronchen2k2k's avatar
aaronchen2k2k 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
}

func testView(cmd string, successRe *regexp.Regexp) string {
	child, err := expect.Spawn(cmd, -1)
	if err != nil {
		return err.Error()
	}
	defer child.Close()

	if _, err = child.Expect(successRe, 10*time.Second); err != nil {
		return fmt.Sprintf("expect %s, actual %s", successRe, err.Error())
	}

	return "Success"
}

func TestCliView(t *testing.T) {
	suite.RunSuite(t, new(ViewSuite))
}