awsmock

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

README

Status work in progress

Use at your own risk!

Taken from https://gist.github.com/Cyberax

Example

func TestGetConfig(t *testing.T){

	AssumeRoleFunc := func(ctx context.Context, params *sts.AssumeRoleInput) (*sts.AssumeRoleOutput, error) {	
			role := *params.RoleArn
			assert.Equal(t,"arn:aws:iam::12345679812:role/aggregate",role)
			return &sts.AssumeRoleOutput{
				Credentials: &types.Credentials{
					AccessKeyId: aws.String("AKAMAI123"),
					SecretAccessKey: aws.String("verysecret"),
					SessionToken: aws.String("tokentoken"),
				},
				},nil
	}
	
	// Create a Mock Handler
	mockCfg := utils.NewAwsMockHandler()
	// add a function to the handler
	// Routing per paramater types
	mockCfg.AddHandler(AssumeRoleFunc)

	client := sts.NewFromConfig(mockCfg.AwsConfig())

	newConfig,_ := aggregate.GetCfgSub(client,"12345679812" )
	creds, _ := newConfig.Credentials.Retrieve(context.TODO())
	assert.Equal(t, "AKAMAI123",creds.AccessKeyID)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertNoErrorPanic

func AssertNoErrorPanic(err error, lines ...string)

AssertNoErrorPanic Assert no error, otherwise panic.

func AssertNoErrorPanicF

func AssertNoErrorPanicF(err error, format string, args ...interface{})

AssertNoErrorPanicF Assert no error, otherwise panic.

func AssertOrPanic

func AssertOrPanic(condition bool, lines ...string)

AssertOrPanic Assert a condition is `true`, otherwise panic.

func AssertOrPanicF

func AssertOrPanicF(condition bool, format string, args ...interface{})

AssertOrPanicF Assert a condition is `true`, otherwise panic.

func CombineErrors

func CombineErrors(err error, errs ...error) error

CombineErrors combines multiple errors into one.

func Error

func Error(lines ...string) error

Error makes an error message.

func ErrorF

func ErrorF(format string, args ...interface{}) error

ErrorF makes an error message.

func FormatError

func FormatError(err error) string

FormatError formats an error.

func Panic

func Panic(lines ...string)

Panic panics with an `error`.

func PanicF

func PanicF(format string, args ...interface{})

PanicF panics with an `error`.

func PanicIf

func PanicIf(condition bool, lines ...string)

PanicIf Assert a condition is `true`, otherwise panic.

func PanicIfF

func PanicIfF(condition bool, format string, args ...interface{})

PanicIfF Assert a condition is `true`, otherwise panic.

Types

type AwsMockHandler

type AwsMockHandler struct {
	// contains filtered or unexported fields
}

func NewAwsMockHandler

func NewAwsMockHandler() *AwsMockHandler

NewAwsMockHandler - Create an AWS mocker to use with the AWS services, it returns an instrumented aws.Config that can be used to create AWS services. You can add as many individual request handlers as you need, as long as handlers correspond to the func(context.Context, <arg>)(<res>, error) format. E.g.: func(context.Context, *ec2.TerminateInstancesInput)(*ec2.TerminateInstancesOutput, error)

You can also use a struct as the handler, in this case the AwsMockHandler will try to search for a method with a conforming signature.

func (*AwsMockHandler) AddHandler

func (a *AwsMockHandler) AddHandler(handlerObject interface{})

func (*AwsMockHandler) AwsConfig

func (a *AwsMockHandler) AwsConfig() aws.Config

type GithooksFailure

type GithooksFailure struct {
	// contains filtered or unexported fields
}

GithooksFailure is a normal hook failure.

func (*GithooksFailure) Error

func (e *GithooksFailure) Error() string

Jump to

Keyboard shortcuts

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