be_url

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 6 Imported by: 0

README

be_url

-- import "github.com/expectto/be/be_url"

Package be_url provides Be matchers on url.URL

Usage

var TransformSchemelessUrlFromString = func(rawURL string) (*url.URL, error) {
	result, err := url.Parse(rawURL)
	if err == nil && result.Scheme == "" {
		result, err = url.Parse("http://" + rawURL)
		if err == nil {
			result.Scheme = ""
		}
	}
	return result, err
}

TransformSchemelessUrlFromString returns string->*url.Url transform It allows string to be a scheme-less url

var TransformUrlFromString = url.Parse

TransformUrlFromString returns string->*url.Url transform

func HavingHost
func HavingHost(args ...any) types.BeMatcher

HavingHost succeeds if the actual value is a *url.URL and its Host matches the provided one (via direct value or matchers)

func HavingHostname
func HavingHostname(args ...any) types.BeMatcher

HavingHostname succeeds if the actual value is a *url.URL and its Hostname matches the provided one (via direct value or matchers)

func HavingMultipleSearchParam
func HavingMultipleSearchParam(searchParamName string, args ...any) types.BeMatcher

HavingMultipleSearchParam succeeds if the actual value is a *url.URL and its specified search parameter (all its values via slice) matches the provided arguments.

func HavingPassword
func HavingPassword(args ...any) types.BeMatcher

HavingPassword succeeds if the actual value is a *url.URL and its Password matches the provided one.

func HavingPath
func HavingPath(args ...any) types.BeMatcher

HavingPath succeeds if the actual value is a *url.URL and its Path matches the given one.

func HavingPort
func HavingPort(args ...any) types.BeMatcher

HavingPort succeeds if the actual value is a *url.URL and its Port matches the provided one.

func HavingRawQuery
func HavingRawQuery(args ...any) types.BeMatcher

HavingRawQuery succeeds if the actual value is a *url.URL and its RawQuery matches the given one.

func HavingScheme
func HavingScheme(args ...any) types.BeMatcher

HavingScheme succeeds if the actual value is a *url.URL and its Scheme matches the provided one (via direct value or matchers)

func HavingSearchParam
func HavingSearchParam(searchParamName string, args ...any) types.BeMatcher

HavingSearchParam succeeds if the actual value is a *url.URL and its specified search parameter matches the provided arguments.

func HavingUserinfo
func HavingUserinfo(args ...any) types.BeMatcher

HavingUserinfo succeeds if the actual value is a *url.URL and its User.String() matches the provided one.

func HavingUsername
func HavingUsername(args ...any) types.BeMatcher

HavingUsername succeeds if the actual value is a *url.URL and its Username matches the provided one.

func NotHavingPort
func NotHavingPort(args ...any) types.BeMatcher

NotHavingPort succeeds if the actual value is a *url.URL and its Port does not match the given one. Example: Expect(u).To(NotHavingPort()) matches port-less url

func NotHavingScheme
func NotHavingScheme(args ...any) types.BeMatcher

NotHavingScheme succeeds if the actual value is a *url.URL and its Scheme negatively matches given value Example: Expect(u).To(NotHavingScheme()) matches url without a scheme

func URL
func URL(args ...any) types.BeMatcher

URL matches actual value to be a valid URL corresponding to given inputs Possible inputs: 1. Nil args -> so actual value MUST be any valid *url.URL 2. Single arg . Actual value MUST be a *url.URL, whose .String() compared against args[0] 3. Single arg <*url.Url>. Actual value MUST be a *url.URL, whose .String() compared against args[0].String() 4. List of Omega/Gomock/Psi matchers, that are applied to *url.URL object

- TransformUrlFromString() transform can be given as first argument, so string->*url.URL transform is applied
func WithHttp
func WithHttp() types.BeMatcher

WithHttp succeeds if the actual value is a *url.URL and its scheme is "http".

func WithHttps
func WithHttps() types.BeMatcher

WithHttps succeeds if the actual value is a *url.URL and its scheme is "https".

Documentation

Overview

Package be_url provides Be matchers on url.URL

Index

Constants

This section is empty.

Variables

View Source
var TransformSchemelessUrlFromString = func(rawURL string) (*url.URL, error) {
	result, err := url.Parse(rawURL)
	if err == nil && result.Scheme == "" {
		result, err = url.Parse("http://" + rawURL)
		if err == nil {
			result.Scheme = ""
		}
	}
	return result, err
}

TransformSchemelessUrlFromString returns string->*url.Url transform It allows string to be a scheme-less url

View Source
var TransformUrlFromString = url.Parse

TransformUrlFromString returns string->*url.Url transform

Functions

func HavingHost

func HavingHost(args ...any) types.BeMatcher

HavingHost succeeds if the actual value is a *url.URL and its Host matches the provided one (via direct value or matchers)

func HavingHostname

func HavingHostname(args ...any) types.BeMatcher

HavingHostname succeeds if the actual value is a *url.URL and its Hostname matches the provided one (via direct value or matchers)

func HavingMultipleSearchParam

func HavingMultipleSearchParam(searchParamName string, args ...any) types.BeMatcher

HavingMultipleSearchParam succeeds if the actual value is a *url.URL and its specified search parameter (all its values via slice) matches the provided arguments.

func HavingPassword

func HavingPassword(args ...any) types.BeMatcher

HavingPassword succeeds if the actual value is a *url.URL and its Password matches the provided one.

func HavingPath

func HavingPath(args ...any) types.BeMatcher

HavingPath succeeds if the actual value is a *url.URL and its Path matches the given one.

func HavingPort

func HavingPort(args ...any) types.BeMatcher

HavingPort succeeds if the actual value is a *url.URL and its Port matches the provided one.

func HavingRawQuery

func HavingRawQuery(args ...any) types.BeMatcher

HavingRawQuery succeeds if the actual value is a *url.URL and its RawQuery matches the given one.

func HavingScheme

func HavingScheme(args ...any) types.BeMatcher

HavingScheme succeeds if the actual value is a *url.URL and its Scheme matches the provided one (via direct value or matchers)

func HavingSearchParam

func HavingSearchParam(searchParamName string, args ...any) types.BeMatcher

HavingSearchParam succeeds if the actual value is a *url.URL and its specified search parameter matches the provided arguments.

func HavingUserinfo

func HavingUserinfo(args ...any) types.BeMatcher

HavingUserinfo succeeds if the actual value is a *url.URL and its User.String() matches the provided one.

func HavingUsername

func HavingUsername(args ...any) types.BeMatcher

HavingUsername succeeds if the actual value is a *url.URL and its Username matches the provided one.

func NotHavingPort

func NotHavingPort(args ...any) types.BeMatcher

NotHavingPort succeeds if the actual value is a *url.URL and its Port does not match the given one. Example: `Expect(u).To(NotHavingPort())` matches port-less url

func NotHavingScheme

func NotHavingScheme(args ...any) types.BeMatcher

NotHavingScheme succeeds if the actual value is a *url.URL and its Scheme negatively matches given value Example: `Expect(u).To(NotHavingScheme())` matches url without a scheme

func URL

func URL(args ...any) types.BeMatcher

URL matches actual value to be a valid URL corresponding to given inputs Possible inputs: 1. Nil args -> so actual value MUST be any valid *url.URL 2. Single arg <string>. Actual value MUST be a *url.URL, whose .String() compared against args[0] 3. Single arg <*url.Url>. Actual value MUST be a *url.URL, whose .String() compared against args[0].String() 4. List of Omega/Gomock/Psi matchers, that are applied to *url.URL object

  • TransformUrlFromString() transform can be given as first argument, so string->*url.URL transform is applied

func WithHttp

func WithHttp() types.BeMatcher

WithHttp succeeds if the actual value is a *url.URL and its scheme is "http".

func WithHttps

func WithHttps() types.BeMatcher

WithHttps succeeds if the actual value is a *url.URL and its scheme is "https".

Types

This section is empty.

Jump to

Keyboard shortcuts

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