cli_extract_test.go 1.9 KB
Newer Older
aaronchen2k2k's avatar
aaronchen2k2k 已提交
1 2 3 4 5 6 7 8 9 10 11
package main

import (
	"fmt"
	"io/ioutil"
	"os"
	"regexp"
	"strings"
	"testing"
	"time"

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

var (
	successExtractRe = regexp.MustCompile("Success to extract test steps and results|成功从注释提取步骤和期待结果")
)

type ExtractSuite struct {
	suite.Suite
}

func (s *ExtractSuite) BeforeEach(t provider.T) {
	t.ID("5430")
Z
zhaoke 已提交
29
	commonTestHelper.ReplaceLabel(t, "命令行-提取分散在脚本中的注释")
aaronchen2k2k's avatar
aaronchen2k2k 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
}
func (s *ExtractSuite) TestExtractSuite(t provider.T) {
	t.Require().Equal("Success", testExtract())
}

func testExtract() string {
	path := fmt.Sprintf(`%sdemo/sample/8_extract_desc.php`, constTestHelper.RootPath)
	cmd := commonTestHelper.GetZtfPath() + ` extract ` + path

	child, err := expect.Spawn(cmd, -1)
	if err != nil {
		return err.Error()
	}
	defer child.Close()

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

	file, err := os.Open(path)
	if err != nil {
		return "File can not open"
	}
	defer file.Close()
	content, err := ioutil.ReadAll(file)
	checkResSuccess := strings.Contains(string(content), `
title=sync step from comments
timeout=0
cid=0

1 >> expect 1

group2
  2.1 >> expect 2.1
  2.2 >> expect 2.2
  2.3 >> expect 2.3  

multi line expect >>
  expect 3.1
  expect 3.2
>>

4 >> expect 4
5 >> expect 5
step 6 >> expect 6
step 7 >> expect 7
step 8 >> expect 8
step 9 >> expect 9
step 10 >> expect 10`)
	if !checkResSuccess {
		return "Check steps error"
	}
	return "Success"
}

func TestCliExtract(t *testing.T) {
	suite.RunSuite(t, new(ExtractSuite))
}