test

package
v0.19.0 Latest Latest
Warning

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

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

Documentation

Overview

Package test contains helper functions for unit testing.

Index

Constants

This section is empty.

Variables

View Source
var (
	Resource1 = []*authorizationpb.IsAuthorizedRequest_Resource{
		{
			ExternalId: "wMDazKCQPNEyETp",
			Type:       "Asset",
			Actions:    []string{"SUBSCRIBES_TO"},
		},
	}

	Resource2 = []*authorizationpb.IsAuthorizedRequest_Resource{
		{
			ExternalId: "wMDazKCQPNEyETp",
			Actions:    []string{"SUBSCRIBES_TO"},
		},
	}

	Resource3 = []*authorizationpb.IsAuthorizedRequest_Resource{
		{
			ExternalId: "wMDazKCQPNEyETp",
			Type:       "Asset",
			Actions:    []string{"DEMANDS"},
		},
	}

	Resource4 = []*authorizationpb.IsAuthorizedRequest_Resource{
		{
			ExternalId: "uqGEnybFZhYYpIf",
			Type:       "Asset",
			Actions:    []string{"SUBSCRIBES_TO"},
		},
	}

	Resource5 = []*authorizationpb.IsAuthorizedRequest_Resource{
		{
			ExternalId: "qlUxezErcaweWss",
			Type:       "Asset",
			Actions:    []string{"SUBSCRIBES_TO"},
		},
	}

	Resource6 = []*authorizationpb.IsAuthorizedRequest_Resource{
		{
			ExternalId: "YPDAQWzzJNlBruc",
			Type:       "Asset",
			Actions:    []string{"SUBSCRIBES_TO"},
		},
	}

	Resource7 = []*authorizationpb.IsAuthorizedRequest_Resource{
		{
			ExternalId: "spriFKHyoNJZMjk",
			Type:       "Asset",
			Actions:    []string{"SUBSCRIBES_TO"},
		},
	}

	Resource8 = []*authorizationpb.IsAuthorizedRequest_Resource{
		{
			ExternalId: "qVdKKwVYYOHVYSW",
			Type:       "Asset",
			Actions:    []string{"SUBSCRIBES_TO"},
		},
	}

	Resource9 = []*authorizationpb.IsAuthorizedRequest_Resource{
		{
			ExternalId: "qVdKKwVYYOHVYSW",
			Type:       "Asset",
			Actions:    []string{"SUBSCRIBES_TO"},
		},
		{
			ExternalId: "YlBquyKoVSYflIx",
			Type:       "Asset",
			Actions:    []string{"SUBSCRIBES_TO"},
		},
	}

	ResourceType1 = []*authorizationpb.WhatAuthorizedRequest_ResourceType{
		{Type: "Asset", Actions: []string{"SUBSCRIBES_TO"}},
	}

	ResourceType2 = []*authorizationpb.WhatAuthorizedRequest_ResourceType{
		{Actions: []string{"SUBSCRIBES_TO", "OWNS"}},
	}

	ResourceType3 = []*authorizationpb.WhatAuthorizedRequest_ResourceType{
		{Type: "Asset", Actions: []string{"DEMANDS"}},
	}

	ResourceWho1 = []*authorizationpb.WhoAuthorizedRequest_Resource{
		{ExternalId: "wMDazKCQPNEyETp", Type: "Asset", Actions: []string{"SUBSCRIBES_TO", "OWNS"}},
	}

	ResourceWho2 = []*authorizationpb.WhoAuthorizedRequest_Resource{
		{Type: "Asset", Actions: []string{"SUBSCRIBES_TO", "OWNS"}},
	}

	ResourceWho3 = []*authorizationpb.WhoAuthorizedRequest_Resource{
		{ExternalId: "wMDazKCQPNEyETp", Type: "Asset", Actions: []string{"DEMANDS", "REPELS"}},
	}

	DigitalTwinBad     = "id"
	DigitalTwinNotInDB = "gid:AAAAGaiIPzg6L0DKkbIh22crsFg"
	DigitalTwin1       = "gid:AAAAFcrHH-xwlEAhr_DYdY-Djj0"
	DigitalTwin2       = "gid:AAAAFeKd8SojW0HrvpmZU8z4aIY"

	EmailBad  = "test@example.com"
	EmailGood = "colas@yahoo.uk"

	ExternalIDGood = "bbbSNydqZpeRiGH"

	Asset1 = "qlUxezErcaweWss"
	Asset2 = "wMDazKCQPNEyETp"
	Asset3 = "qVdKKwVYYOHVYSW"

	Subject1 = "QNcLrJCLGjIbpYO"
	Subject2 = "bbbSNydqZpeRiGH"
	Subject3 = "uKcftQKZQfvvGoC"

	// TokenGoodFormat is a valid format for jwt.
	TokenGoodFormat = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9." +
		"eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9." +
		"dyt0CoTl4WoVjAHI9Q_CwSKhl6d_9rhM3NrXuJttkao" // #nosec G101
	TokenBad = "token_invalid_format"

	WrongTenant              = "gid:AAAAA8YwJJujqkUAuTA6pR0AVbM"
	WrongTenantOtherAppSpace = "gid:AAAAA_2EBAWjakSCo5hf_WIi1oI"
)

Functions

func BeBase64

func BeBase64() types.GomegaMatcher

BeBase64 match string if it is Base64 Standard encoded.

func CreateRecordIndividual added in v0.18.0

func CreateRecordIndividual(tenantID,
	role string) (*ingestpb.Record, string)

func CreateRecordNoProp added in v0.18.0

func CreateRecordNoProp(externalID, tenantID, nodeType string) *ingestpb.Record

func CreateRecordRelation added in v0.18.0

func CreateRecordRelation(
	sourceExternalID string,
	sourceType string,
	targetExternalID string,
	targetType string,
	relationType string) *ingestpb.Record

func CreateRecordResourceNoProp added in v0.18.0

func CreateRecordResourceNoProp(externalID, nodeType string) *ingestpb.Record

func DeleteRecord added in v0.18.0

func DeleteRecord(externalID, nodeType string) *ingestpb.Record

func DeleteRecordProperty added in v0.18.0

func DeleteRecordProperty(externalID, nodeType, property string) *ingestpb.Record

func DeleteRecordRelation added in v0.18.0

func DeleteRecordRelation(match *ingestpb.RelationMatch) *ingestpb.Record

func DeleteRecordRelationProperty added in v0.18.0

func DeleteRecordRelationProperty(match *ingestpb.RelationMatch, property string) *ingestpb.Record

func EqualAnyProto

func EqualAnyProto(expected protoreflect.ProtoMessage) types.GomegaMatcher

EqualAnyProto uses proto.Equal to compare actual with expected. Equal is strict about types when performing comparisons. It is an error for both actual and expected to be nil. Use BeNil() instead.

func EqualProto

func EqualProto(expected protoreflect.ProtoMessage) types.GomegaMatcher

EqualProto uses proto.Equal to compare actual with expected. Equal is strict about types when performing comparisons. It is an error for both actual and expected to be nil. Use BeNil() instead.

func GenerateRandomString added in v0.18.0

func GenerateRandomString(length int) string

func GetRelationMatch added in v0.18.0

func GetRelationMatch(
	sourceExternalID string,
	sourceType string,
	targetExternalID string,
	targetType string,
	relationType string) *ingestpb.RelationMatch

func InitConfigAuthorization added in v0.18.0

func InitConfigAuthorization() (*authorization.Client, error)

InitConfigAuthorization reads in config file and ENV variables if set.

func InitConfigIngest added in v0.18.0

func InitConfigIngest() (*ingest.Client, error)

InitConfigIngest reads in ingest file and ENV variables if set.

func InitConfigIngestRetry added in v0.18.0

func InitConfigIngestRetry() (*ingest.RetryClient, error)

InitConfigIngestRetry reads in ingest file and ENV variables if set.

func MatchErrorCode

func MatchErrorCode(errorCode codes.Code) types.GomegaMatcher

MatchErrorCode succeeds if actual is a non-nil error that has the code the passed in error.

Error must be google.golang.org/grpc/status.Error It is an error for err to be nil or an object that does not implement the Error interface.

func MatchJSON

func MatchJSON(expected any) types.GomegaMatcher

MatchJSON uses the expected value to build a value matcher.

func MatchProtoMessage

func MatchProtoMessage(message proto.Message) types.GomegaMatcher

MatchProtoMessage succeeds if.

func MatchStatusError

func MatchStatusError(errorCode codes.Code, msg any) types.GomegaMatcher

MatchStatusError succeeds if actual is a non-nil error that has the code the passed in error.

Error must be google.golang.org/grpc/status.Error It is an error for err to be nil or an object that does not implement the Error interface.

func UpsertRecordAsset added in v0.18.0

func UpsertRecordAsset() (*ingestpb.Record, string)

func WrapMatcher added in v0.14.0

func WrapMatcher(matcher types.GomegaMatcher) gomock.Matcher

Types

type EqualAnyProtoMatcher

type EqualAnyProtoMatcher struct {
	Expected proto.Message
	// contains filtered or unexported fields
}

func (*EqualAnyProtoMatcher) FailureMessage

func (matcher *EqualAnyProtoMatcher) FailureMessage(any) string

func (*EqualAnyProtoMatcher) Match

func (matcher *EqualAnyProtoMatcher) Match(actual any) (bool, error)

func (*EqualAnyProtoMatcher) NegatedFailureMessage

func (matcher *EqualAnyProtoMatcher) NegatedFailureMessage(any) string

type EqualProtoMatcher

type EqualProtoMatcher struct {
	Expected proto.Message
}

func (*EqualProtoMatcher) FailureMessage

func (matcher *EqualProtoMatcher) FailureMessage(actual any) string

func (*EqualProtoMatcher) GomegaString

func (matcher *EqualProtoMatcher) GomegaString() string

func (*EqualProtoMatcher) Match

func (matcher *EqualProtoMatcher) Match(actual any) (bool, error)

func (*EqualProtoMatcher) NegatedFailureMessage

func (matcher *EqualProtoMatcher) NegatedFailureMessage(actual any) string

type MatchJSONMatcher

type MatchJSONMatcher struct {
	types.GomegaMatcher
}

func (*MatchJSONMatcher) Match

func (matcher *MatchJSONMatcher) Match(actual any) (bool, error)

type MatchProtoMessageMatcher

type MatchProtoMessageMatcher struct {
	Expected proto.Message
}

func (*MatchProtoMessageMatcher) FailureMessage

func (matcher *MatchProtoMessageMatcher) FailureMessage(actual any) string

func (*MatchProtoMessageMatcher) Match

func (matcher *MatchProtoMessageMatcher) Match(actual any) (bool, error)

func (*MatchProtoMessageMatcher) NegatedFailureMessage

func (matcher *MatchProtoMessageMatcher) NegatedFailureMessage(actual any) string

type MatchSDKStatusErrorMatcher

type MatchSDKStatusErrorMatcher struct {
	Expected codes.Code
	// contains filtered or unexported fields
}

func (*MatchSDKStatusErrorMatcher) FailureMessage

func (matcher *MatchSDKStatusErrorMatcher) FailureMessage(actual any) string

func (*MatchSDKStatusErrorMatcher) Match

func (matcher *MatchSDKStatusErrorMatcher) Match(actual any) (bool, error)

func (*MatchSDKStatusErrorMatcher) NegatedFailureMessage

func (matcher *MatchSDKStatusErrorMatcher) NegatedFailureMessage(actual any) string

Directories

Path Synopsis
authorization
v1beta1
Code generated by MockGen.
Code generated by MockGen.
config
v1beta1
Code generated by MockGen.
Code generated by MockGen.
identity
v1beta2
Code generated by MockGen.
Code generated by MockGen.
ingest
v1beta2
Code generated by MockGen.
Code generated by MockGen.
knowledge
v1beta1
Code generated by MockGen.
Code generated by MockGen.

Jump to

Keyboard shortcuts

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