rpctest

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TestAPIVersion = "2023-10-01-preview"
)

Variables

This section is empty.

Functions

func AssertRequests

func AssertRequests(t *testing.T, tests []HandlerTestSpec, pathBase, rootScope string, configureRouter func(context.Context) (chi.Router, error))

AssertRequests asserts that the restful APIs matches the routes and its operation type matches the given test cases. This is working only for test controllers. If you want to validate the routes for the real controllers, use AssertRouters.

func AssertRouters

func AssertRouters(t *testing.T, tests []HandlerTestSpec, pathBase, rootScope string, configureRouter func(context.Context) (chi.Router, error))

AssertRouters asserts that the given router matches the given test cases.

func FakeStoreObject

func FakeStoreObject(dm v1.DataModelInterface) *store.Object

FakeStoreObject creates store.Object for datamodel.

func MustParseOperationType

func MustParseOperationType(operationType string) v1.OperationType

MustParseOperationType parses the operation type or panics if it fails.

func NewARMRequestContext

func NewARMRequestContext(req *http.Request) context.Context

NewARMRequestContext extracts context from http request, adds ARMRequestContext to it, and return a new context.

func NewHTTPRequestFromJSON

func NewHTTPRequestFromJSON(ctx context.Context, method string, headerFixtureJSONFile string, body any) (*http.Request, error)

NewHTTPRequestFromJSON returns a new HTTP request with the given JSON file as a body content.

func NewHTTPRequestWithContent

func NewHTTPRequestWithContent(ctx context.Context, method string, url string, body []byte) (*http.Request, error)

NewHTTPRequestWithContent returns a new HTTP request with the given body content.

func TestResourceDataModelToVersioned

func TestResourceDataModelToVersioned(model *TestResourceDataModel, version string) (v1.VersionedModelInterface, error)

Types

type ControllerContext

type ControllerContext struct {
	Ctx    context.Context
	MCtrl  *gomock.Controller
	MockSC *store.MockStorageClient
	MockSP *dataprovider.MockDataStorageProvider
}

ControllerContext represents the context of controller tests including common mocks.

func NewControllerContext

func NewControllerContext(t *testing.T) *ControllerContext

NewControllerContext creates a new ControllerContext for testing.

type HandlerTestSpec

type HandlerTestSpec struct {
	// OperationType is the operation type of the request.
	OperationType v1.OperationType
	// Path is the sub path of the router matches.
	Path string
	// Method is the HTTP method of the request.
	Method string
	// WithoutRootScope indicates that the root scope should not be prepended to the path.
	WithoutRootScope bool
	// SkipPathBase indicates that the path base should not be prepended to the path.
	SkipPathBase bool
	// SkipOperationTypeValidation indicates that the operation type should not be validated.
	SkipOperationTypeValidation bool
}

HandlerTestSpec is a specification for a single test case for a handler.

type TestResource

type TestResource struct {
	ID         *string                 `json:"id,omitempty"`
	Name       *string                 `json:"name,omitempty"`
	SystemData *v1.SystemData          `json:"systemData,omitempty"`
	Type       *string                 `json:"type,omitempty"`
	Location   *string                 `json:"location,omitempty"`
	Properties *TestResourceProperties `json:"properties,omitempty"`
	Tags       map[string]*string      `json:"tags,omitempty"`
}

TestResource represents test resource for api version.

func (*TestResource) ConvertFrom

func (dst *TestResource) ConvertFrom(src v1.DataModelInterface) error

Function Explanation

ConvertFrom converts src version agnostic model to versioned model, TestResource.

func (*TestResource) ConvertTo

func (src *TestResource) ConvertTo() (v1.DataModelInterface, error)

Function Explanation

ConvertTo converts a version specific TestResource into a version-agnostic resource, TestResourceDataModel.

type TestResourceDataModel

type TestResourceDataModel struct {
	v1.BaseResource

	// Properties is the properties of the resource.
	Properties *TestResourceDataModelProperties `json:"properties"`
}

TestResourceDataModel represents test resource.

func TestResourceDataModelFromVersioned

func TestResourceDataModelFromVersioned(content []byte, version string) (*TestResourceDataModel, error)

func (*TestResourceDataModel) ResourceTypeName

func (r *TestResourceDataModel) ResourceTypeName() string

ResourceTypeName returns the qualified name of the resource

type TestResourceDataModelProperties

type TestResourceDataModelProperties struct {
	Application string `json:"application"`
	Environment string `json:"environment"`
	PropertyA   string `json:"propertyA,omitempty"`
	PropertyB   string `json:"propertyB,omitempty"`
}

TestResourceDataModelProperties represents the properties of TestResourceDataModel.

type TestResourceProperties

type TestResourceProperties struct {
	ProvisioningState *v1.ProvisioningState `json:"provisioningState,omitempty"`
	Environment       *string               `json:"environment,omitempty"`
	Application       *string               `json:"application,omitempty"`
	PropertyA         *string               `json:"propertyA,omitempty"`
	PropertyB         *string               `json:"propertyB,omitempty"`
}

TestResourceProperties - HTTP Route properties

Jump to

Keyboard shortcuts

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