framework

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2023 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserAdmin        = "admin"
	UserTenantAdmin  = "tenantAdmin"
	UserProjectAdmin = "projectAdmin"
	UserNormal       = "user"

	MultiConfig = "multiConfig.yaml"

	ResourceReady  = "resourceReady"
	ResourceFailed = "resourceFailed"

	WorkerNum = "workerNum"
)

Variables

View Source
var (
	// cluster
	TargetClusterName string
	PivotClusterName  string
	// quota
	CubeResourceQuota string
	// host
	KubecubeHost string
	ConsoleHost  string
	// tenant
	TenantName    string
	ProjectName   string
	NamespaceName string
	// user
	Admin                string
	AdminPassword        string
	TenantAdmin          string
	TenantAdminPassword  string
	ProjectAdmin         string
	ProjectAdminPassword string
	User                 string
	UserPassword         string
	// timeout
	WaitInterval       time.Duration
	WaitTimeout        time.Duration
	HttpRequestTimeout time.Duration
	// pv
	PVEnabled bool
	// CloudShellEnabled cloudShell
	CloudShellEnabled bool
	// workload
	CronJobEnable     bool
	DaemonSetEnable   bool
	DeploymentEnable  bool
	JobEnable         bool
	StatefulSetEnable bool
	NodeHostName      string
	NodeHostIp        string
	TestImage         string
	ImagePullSecret   string
	StorageClass      string
	// hub
	Registry string
	Username string
	Password string
	Email    string
	// PivotClusterClient communicate with pivot cluster
	PivotClusterClient client.Client
	PivotConvertClient ctrlclient.Client

	// TargetClusterClient communicate with target cluster
	TargetClusterClient client.Client
	TargetConvertClient ctrlclient.Client

	KubeCubeSystem string
	KubeCubeE2ECM  string
	LoginType      string
)
View Source
var (
	ToTestMap  = make(map[string]map[string]MultiUserTestStep)
	TestUser   []string
	TestConfig = make(map[string]MultiUserTest)
)
View Source
var AllTestMap = make(map[string]struct{})
View Source
var ConfigHelper = make([]MultiUserTest, 0)
View Source
var SucceedResp = TestResp{
	Err:  nil,
	Data: "",
}

Functions

func BuildRequest

func BuildRequest(method, urlVal, data string, header map[string]string) (*http.Request, error)

func CreateNamespace

func CreateNamespace(baseName string, cli client.Client) (*v1.Namespace, error)

CreateNamespace Create namespace

func CreateSecret

func CreateSecret() error

func CreateTestExample

func CreateTestExample(test MultiUserTest) error

func DefaultErrorFunc

func DefaultErrorFunc(resp TestResp)

func DefaultSkipFunc

func DefaultSkipFunc() bool

func DeleteNamespace

func DeleteNamespace(ns *v1.Namespace, cli client.Client) error

DeleteNamespace Delete Namespace

func ExpectConsistOf

func ExpectConsistOf(actual interface{}, extra interface{}, explain ...interface{})

ExpectConsistOf expects actual contains precisely the extra elements. The ordering of the elements does not matter.

func ExpectEmpty

func ExpectEmpty(actual interface{}, explain ...interface{})

ExpectEmpty expects actual is empty

func ExpectEqual

func ExpectEqual(actual interface{}, extra interface{}, explain ...interface{})

ExpectEqual expects the specified two are the same, otherwise an exception raises

func ExpectError

func ExpectError(err error, explain ...interface{})

ExpectError expects an error happens, otherwise an exception raises

func ExpectHaveKey

func ExpectHaveKey(actual interface{}, key interface{}, explain ...interface{})

ExpectHaveKey expects the actual map has the key in the keyset

func ExpectNoError

func ExpectNoError(err error, explain ...interface{})

ExpectNoError checks if "err" is set, and if so, fails assertion while logging the error.

func ExpectNoErrorWithOffset

func ExpectNoErrorWithOffset(offset int, err error, explain ...interface{})

ExpectNoErrorWithOffset checks if "err" is set, and if so, fails assertion while logging the error at "offset" levels above its caller (for example, for call chain f -> g -> ExpectNoErrorWithOffset(1, ...) error would be logged for "f").

func ExpectNotEqual

func ExpectNotEqual(actual interface{}, extra interface{}, explain ...interface{})

ExpectNotEqual expects the specified two are not the same, otherwise an exception raises

func GetAllUsersAvailable

func GetAllUsersAvailable() []string

func GetUser

func GetUser(user string) string

func InitGlobalV

func InitGlobalV() error

InitGlobalV 初始化全局变量

func InitMultiConfig

func InitMultiConfig() error

func IsSuccess

func IsSuccess(code int) bool

func NameWithUser

func NameWithUser(name, user string) string

func OutputMultiUserTestConfig

func OutputMultiUserTestConfig(path string) error

func PermissionErrorFunc

func PermissionErrorFunc(resp TestResp)

func PostFile

func PostFile(filename string, fieldName string, target_url string, header map[string]string) (*http.Response, error)

func Register

func Register(key string, loginFunc LoginByUser)

func RegisterByDefault

func RegisterByDefault(test MultiUserTest)

func RegisterTestAndSteps

func RegisterTestAndSteps(test MultiUserTest) error

func UserContains

func UserContains(user string) bool

Types

type AuthUser

type AuthUser struct {
	Username string
	Password string
	Token    string
	Cookie   *http.Cookie
}

type GeneralLogin

type GeneralLogin struct{}

func (*GeneralLogin) AuthHeader

func (g *GeneralLogin) AuthHeader() string

func (*GeneralLogin) LoginByUser

func (g *GeneralLogin) LoginByUser(user *AuthUser) error

type HttpHelper

type HttpHelper struct {
	Admin        AuthUser
	TenantAdmin  AuthUser
	ProjectAdmin AuthUser
	User         AuthUser
	Client       http.Client
	AuthHeader   string
}

func NewHttpHelper

func NewHttpHelper() *HttpHelper

func NewSingleHttpHelper

func NewSingleHttpHelper() *HttpHelper

single mode

func (*HttpHelper) BuildRequest

func (h *HttpHelper) BuildRequest(method, urlVal, data, user string, header map[string]string) (*http.Request, error)

build request

func (*HttpHelper) Delete

func (h *HttpHelper) Delete(urlVal string) (*http.Response, error)

delete

func (*HttpHelper) Get

func (h *HttpHelper) Get(urlVal string, header map[string]string) (*http.Response, error)

get

func (*HttpHelper) Login

func (h *HttpHelper) Login(login string) *HttpHelper

func (*HttpHelper) MultiUserRequest

func (h *HttpHelper) MultiUserRequest(method, url, body string, header map[string]string) map[string]MultiRequestResponse

multi user request test

func (*HttpHelper) Patch

func (h *HttpHelper) Patch(urlVal, body string, header map[string]string) (*http.Response, error)

func (*HttpHelper) Post

func (h *HttpHelper) Post(urlVal, body string, header map[string]string) (*http.Response, error)

post

func (*HttpHelper) Put

func (h *HttpHelper) Put(urlVal, body string, header map[string]string) (*http.Response, error)

put

func (*HttpHelper) Request

func (h *HttpHelper) Request(method, urlVal, data string, header map[string]string) (*http.Response, error)

default request by admin

func (*HttpHelper) RequestByUser

func (h *HttpHelper) RequestByUser(method, urlVal, data, user string, header map[string]string) (*http.Response, error)

request by user

type LoginByUser

type LoginByUser interface {
	LoginByUser(user *AuthUser) error
	AuthHeader() string
}

func GetLoginMap

func GetLoginMap(key string) LoginByUser

type MultiRequestResponse

type MultiRequestResponse struct {
	Resp *http.Response
	Err  error
}

type MultiUserTest

type MultiUserTest struct {
	TestName        string              `yaml:"testName"`
	ContinueIfError bool                `yaml:"continueIfError"`
	Steps           []MultiUserTestStep `yaml:"steps"`
	SkipUsers       []string            `yaml:"skipUsers"`
	BeforeEach      func()              `yaml:"-"`
	AfterEach       func()              `yaml:"-"`
	Skipfunc        func() bool         `yaml:"-"`
	ErrorFunc       func(resp TestResp) `yaml:"-"`
	InitStep        *MultiUserTestStep  `yaml:"-"`
	FinalStep       *MultiUserTestStep  `yaml:"-"`
}

type MultiUserTestConfig

type MultiUserTestConfig struct {
	AllUsers []string        `yaml:"allUsers"`
	TestMap  []MultiUserTest `yaml:"testMap"`
}

type MultiUserTestStep

type MultiUserTestStep struct {
	Name        string          `yaml:"name"`
	Description string          `yaml:"description"`
	StepFunc    TestFunc        `yaml:"-"`
	ExpectPass  map[string]bool `yaml:"expectPass,omitempty"`
}

type TestFunc

type TestFunc func(user string) TestResp

type TestResp

type TestResp struct {
	Err  error
	Data interface{}
}

func NewTestResp

func NewTestResp(err error, data interface{}) TestResp

func NewTestRespWithErr

func NewTestRespWithErr(err error) TestResp

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL