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

import (
	"fmt"
	zentaoHelper "github.com/easysoft/zentaoatf/internal/pkg/helper/zentao"
	constTestHelper "github.com/easysoft/zentaoatf/test/helper/conf"
	httpHelper "github.com/easysoft/zentaoatf/test/helper/http"
8
	"github.com/easysoft/zentaoatf/test/restapi/config"
aaronchen2k2k's avatar
aaronchen2k2k 已提交
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
	"github.com/ozontech/allure-go/pkg/framework/provider"
	"github.com/ozontech/allure-go/pkg/framework/suite"
	"github.com/tidwall/gjson"
	"testing"
)

func TestSuiteApi(t *testing.T) {
	suite.RunSuite(t, new(SuiteApiSuite))
}

type SuiteApiSuite struct {
	suite.Suite
}

func (s *SuiteApiSuite) BeforeEach(t provider.T) {
	t.AddSubSuite("SuiteApi")
}

func (s *SuiteApiSuite) TestSuiteListApi(t provider.T) {
28
	t.ID("7622")
aaronchen2k2k's avatar
aaronchen2k2k 已提交
29 30
	token := httpHelper.Login()

31
	url := zentaoHelper.GenApiUrl(fmt.Sprintf("products/%d/testsuites", config.ProductId), nil, constTestHelper.ZentaoSiteUrl)
aaronchen2k2k's avatar
aaronchen2k2k 已提交
32 33 34 35 36 37 38 39 40

	bodyBytes, _ := httpHelper.Get(url, token)

	firstSuiteId := gjson.Get(string(bodyBytes), "testsuites.0.id").Int()

	t.Require().Greater(firstSuiteId, int64(0), "list testsuite failed")
}

func (s *SuiteApiSuite) TestSuiteDetailApi(t provider.T) {
41
	t.ID("7623")
aaronchen2k2k's avatar
aaronchen2k2k 已提交
42 43
	token := httpHelper.Login()

44
	url := zentaoHelper.GenApiUrl(fmt.Sprintf("testsuites/%d", config.SuiteId), nil, constTestHelper.ZentaoSiteUrl)
aaronchen2k2k's avatar
aaronchen2k2k 已提交
45 46 47 48 49 50 51

	bodyBytes, _ := httpHelper.Get(url, token)

	name := gjson.Get(string(bodyBytes), "name").String()

	t.Require().Greater(len(name), 0, "get testsuite failed")
}
aaronchen2k2k's avatar
aaronchen2k2k 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

func getSuiteMinId() (id int64) {
	token := httpHelper.Login()

	url := zentaoHelper.GenApiUrl(fmt.Sprintf("products/%d/testsuites", config.ProductId), nil, constTestHelper.ZentaoSiteUrl)

	bodyBytes, _ := httpHelper.Get(url, token)

	suites := gjson.Get(string(bodyBytes), "testsuites").Array()
	for _, suite := range suites {
		suiteId := suite.Get("id").Int()
		if id == 0 || (suiteId > 0 && id > suiteId) {
			id = suiteId
		}
	}

	return
}