framework

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2021 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Copyright 2021 KubeCube Authors

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

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 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

func (*Framework) ReadEnvConfig

func (f *Framework) ReadEnvConfig()

Read env config

type HttpHelper

type HttpHelper struct {
	HostPath     string
	Admin        string
	TenantAdmin  string
	ProjectAdmin string
	User         string
	Client       http.Client
	Cookies      []*http.Cookie
}

func NewHttpHelper

func NewHttpHelper() *HttpHelper

func (*HttpHelper) FormatUrl

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

func (*HttpHelper) Login

func (h *HttpHelper) Login() *HttpHelper

func (*HttpHelper) LoginByUser

func (h *HttpHelper) LoginByUser(username string) *HttpHelper

func (*HttpHelper) MultiUserRequest

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

multi user request test

func (*HttpHelper) Request

func (h *HttpHelper) Request(method, urlVal, data string) http.Request

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