framework

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WaitInterval = 2 * time.Second
	WaitTimeout  = 120 * time.Second
)

Variables

This section is empty.

Functions

func CreateNamespace

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

Create namespace

func DeleteNamespace

func DeleteNamespace(ns *v1.Namespace) error

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

Types

type AuthUser added in v1.1.0

type AuthUser struct {
	Username string
	Ak       string
	Sk       string
	Token    string
	Cookies  []*http.Cookie
	AuthType int // 0 cookie, 1 token
}

type Framework

type Framework struct {
	BaseName string

	// Http client
	Host       string
	HttpHelper *HttpHelper

	// Timeouts contains the custom timeouts used during the test execution.
	Timeouts *TimeoutContext

	// preset tenant/project/namespace
	TenantName  string
	ProjectName string
	Namespace   string
}

Framework supports common operations used by e2e tests; it will keep a client & a namespace for you.

func NewDefaultFramework

func NewDefaultFramework(baseName string) *Framework

NewFramework creates a test framework and sets up a BeforeEach/AfterEach for you (you can write additional before/after each functions).

func NewFramework

func NewFramework(baseName string) *Framework

type HttpHelper

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

func NewHttpHelper

func NewHttpHelper() *HttpHelper

func NewSingleHttpHelper added in v1.1.0

func NewSingleHttpHelper() *HttpHelper

single mode

func (*HttpHelper) AuthToken added in v1.1.0

func (h *HttpHelper) AuthToken() *HttpHelper

get token

func (*HttpHelper) Delete added in v1.1.0

func (h *HttpHelper) Delete(urlVal string) http.Request

delete

func (*HttpHelper) FormatUrl

func (h *HttpHelper) FormatUrl(url string) string

format url

func (*HttpHelper) Get added in v1.1.0

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

get

func (*HttpHelper) GetToken added in v1.1.0

func (h *HttpHelper) GetToken(user *AuthUser) error

get token by ak sk

func (*HttpHelper) Login

func (h *HttpHelper) Login() *HttpHelper

func (*HttpHelper) LoginByUser

func (h *HttpHelper) LoginByUser(user *AuthUser) error

func (*HttpHelper) MultiUserRequest

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

multi user request test

func (*HttpHelper) Post added in v1.1.0

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

post

func (*HttpHelper) Put added in v1.1.0

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

put

func (*HttpHelper) Request

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

default request by admin

func (*HttpHelper) RequestByUser added in v1.1.0

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

request by admin\tenantAdmin\projectAdmin\user

type MultiRequestResponse

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

type TimeoutContext

type TimeoutContext struct {
	// HttpRequest is how long to wait for the http request
	HttpRequest time.Duration

	// ResourceCreate is how long to wait for resource creation
	// Use it in case create fail and hold
	WaitInterval time.Duration

	// ResourceCreate is how long to wait for resource delete
	// Use it in case delete fail and hold
	WaitTimeout time.Duration
}

TimeoutContext contains timeout settings for several actions.

func NewTimeoutContextWithDefaults

func NewTimeoutContextWithDefaults() *TimeoutContext

NewTimeoutContextWithDefaults returns a TimeoutContext with default values.

Jump to

Keyboard shortcuts

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