testutils

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2021 License: AGPL-3.0 Imports: 33 Imported by: 0

README

testutils

This provides some convenience methods for writing integration tests.

Functions

  • ClearDynamoTable(awsSession, tableName string) - Delete all items in a DynamoDB table
  • ClearS3Bucket(awsSession, bucketName string) - Delete all object versions in an S3 bucket

Example Integration Test

package main

import (
    "flag"
    "os"
    "testing"

    "github.com/aws/aws-sdk-go/aws/session"
    "github.com/stretchr/testify/require"

    "github.com/panther-labs/panther/pkg/testutils"
)

var (
    awsSession      = session.Must(session.NewSession())
    integrationFlag = flag.Bool("integration", false, "run integration tests")
)

func TestMain(m *testing.M) {
    flag.Parse()
    os.Exit(m.Run())
}

func TestIntegrationAPI(t *testing.T) {
    if !*integrationFlag {
        t.Skip()
    }

    // Reset backend state - erase dynamo table and S3 bucket
    require.NoError(t, testutils.ClearDynamoTable(awsSession, "panther-rules-table"))
    require.NoError(t, testutils.ClearS3Bucket(awsSession, "panther-rules-bucket"))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearDynamoTable

func ClearDynamoTable(awsSession *session.Session, tableName string) error

ClearDynamoTable deletes all items from the table.

Automatic table backups are not affected.

func ClearS3Bucket

func ClearS3Bucket(awsSession *session.Session, bucketName string) error

ClearS3Bucket deletes all object versions from the bucket.

func IntegrationTest added in v1.15.0

func IntegrationTest(t *testing.T)

IntegrationTest skips the current test if the env variable INTEGRATION_TEST is not set to "true".

Types

type AthenaMock added in v1.4.0

type AthenaMock struct {
	athenaiface.AthenaAPI
	mock.Mock
}

func (*AthenaMock) GetQueryExecution added in v1.4.0

func (*AthenaMock) GetQueryResults added in v1.4.0

func (*AthenaMock) ListTableMetadataPagesWithContext added in v1.16.0

func (m *AthenaMock) ListTableMetadataPagesWithContext(ctx aws.Context, input *athena.ListTableMetadataInput,
	f func(*athena.ListTableMetadataOutput, bool) bool, option ...request.Option) error

func (*AthenaMock) StartQueryExecution added in v1.4.0

type CounterMock added in v1.16.0

type CounterMock struct {
	metrics.Counter
	mock.Mock
}

func (*CounterMock) Add added in v1.16.0

func (m *CounterMock) Add(delta float64)

func (*CounterMock) With added in v1.16.0

func (m *CounterMock) With(dimensionValues ...string) metrics.Counter

type DynamoDBMock added in v1.1.0

type DynamoDBMock struct {
	dynamodbiface.DynamoDBAPI
	mock.Mock
}

func (*DynamoDBMock) DeleteItem added in v1.3.0

func (*DynamoDBMock) GetItem added in v1.3.0

func (*DynamoDBMock) PutItem added in v1.1.0

func (*DynamoDBMock) Query added in v1.14.0

func (*DynamoDBMock) Scan added in v1.3.0

func (*DynamoDBMock) UpdateItem added in v1.1.0

type EventBridgeMock added in v1.3.0

type EventBridgeMock struct {
	eventbridgeiface.EventBridgeAPI
	mock.Mock
}

func (*EventBridgeMock) DeleteRule added in v1.3.0

func (*EventBridgeMock) ListEventBuses added in v1.3.0

func (*EventBridgeMock) PutRule added in v1.3.0

func (*EventBridgeMock) PutTargets added in v1.3.0

func (*EventBridgeMock) RemoveTargets added in v1.3.0

type FirehoseMock added in v1.6.0

type FirehoseMock struct {
	firehoseiface.FirehoseAPI
	mock.Mock
}

func (*FirehoseMock) PutRecordBatchWithContext added in v1.6.0

func (m *FirehoseMock) PutRecordBatchWithContext(
	ctx aws.Context,
	input *firehose.PutRecordBatchInput,
	options ...request.Option) (*firehose.PutRecordBatchOutput, error)

type GatewayapiMock added in v1.15.0

type GatewayapiMock struct {
	gatewayapi.API
	mock.Mock
}

func (*GatewayapiMock) Invoke added in v1.15.0

func (g *GatewayapiMock) Invoke(input, output interface{}) (int, error)

type GlueMock added in v1.2.0

type GlueMock struct {
	glueiface.GlueAPI
	mock.Mock
	LogTables []*glue.TableData
}

func (*GlueMock) CreateDatabase added in v1.14.0

func (m *GlueMock) CreateDatabase(input *glue.CreateDatabaseInput) (*glue.CreateDatabaseOutput, error)

func (*GlueMock) CreateDatabaseWithContext added in v1.14.0

func (m *GlueMock) CreateDatabaseWithContext(
	ctx context.Context,
	input *glue.CreateDatabaseInput,
	options ...request.Option,
) (*glue.CreateDatabaseOutput, error)

func (*GlueMock) CreatePartition added in v1.2.0

func (m *GlueMock) CreatePartition(input *glue.CreatePartitionInput) (*glue.CreatePartitionOutput, error)

func (*GlueMock) CreateTable added in v1.4.0

func (m *GlueMock) CreateTable(input *glue.CreateTableInput) (*glue.CreateTableOutput, error)

func (*GlueMock) CreateTableWithContext added in v1.15.0

func (m *GlueMock) CreateTableWithContext(ctx context.Context,
	input *glue.CreateTableInput, _ ...request.Option) (*glue.CreateTableOutput, error)

func (*GlueMock) DeleteTable added in v1.2.0

func (m *GlueMock) DeleteTable(input *glue.DeleteTableInput) (*glue.DeleteTableOutput, error)

func (*GlueMock) GetPartition added in v1.2.0

func (m *GlueMock) GetPartition(input *glue.GetPartitionInput) (*glue.GetPartitionOutput, error)

func (*GlueMock) GetPartitions added in v1.3.0

func (m *GlueMock) GetPartitions(input *glue.GetPartitionsInput) (*glue.GetPartitionsOutput, error)

func (*GlueMock) GetTable added in v1.2.0

func (m *GlueMock) GetTable(input *glue.GetTableInput) (*glue.GetTableOutput, error)

func (*GlueMock) GetTablesPagesWithContext added in v1.11.0

func (m *GlueMock) GetTablesPagesWithContext(
	ctx aws.Context,
	input *glue.GetTablesInput,
	scan func(page *glue.GetTablesOutput, isLast bool) bool,
	_ ...request.Option,
) error

nolint:lll

func (*GlueMock) UpdatePartition added in v1.2.0

func (m *GlueMock) UpdatePartition(input *glue.UpdatePartitionInput) (*glue.UpdatePartitionOutput, error)

type LambdaMock added in v1.0.0

type LambdaMock struct {
	lambdaiface.LambdaAPI
	mock.Mock
}

func (*LambdaMock) CreateEventSourceMapping added in v1.6.0

func (*LambdaMock) DeleteEventSourceMapping added in v1.6.0

func (*LambdaMock) Invoke added in v1.0.0

func (m *LambdaMock) Invoke(input *lambda.InvokeInput) (*lambda.InvokeOutput, error)

func (*LambdaMock) InvokeWithContext added in v1.12.0

func (m *LambdaMock) InvokeWithContext(
	ctx aws.Context,
	input *lambda.InvokeInput,
	options ...request.Option) (*lambda.InvokeOutput, error)

func (*LambdaMock) ListEventSourceMappings added in v1.6.0

type LoggerMock added in v1.13.0

type LoggerMock struct {
	metrics.Logger
	mock.Mock
}

func (*LoggerMock) Log added in v1.13.0

func (m *LoggerMock) Log(dimensions []metrics.Dimension, metrics ...metrics.Metric)

type MetricsManagerMock added in v1.16.0

type MetricsManagerMock struct {
	metrics.Manager
	mock.Mock
}

func (*MetricsManagerMock) NewCounter added in v1.16.0

func (m *MetricsManagerMock) NewCounter(name, unit string) metrics.Counter

func (*MetricsManagerMock) Run added in v1.16.0

func (m *MetricsManagerMock) Run(ctx context.Context, interval time.Duration)

func (*MetricsManagerMock) Sync added in v1.16.0

func (m *MetricsManagerMock) Sync() error

type S3Mock added in v1.0.0

type S3Mock struct {
	s3iface.S3API
	mock.Mock
}

func (*S3Mock) DeleteObjects added in v1.13.0

func (m *S3Mock) DeleteObjects(input *s3.DeleteObjectsInput) (*s3.DeleteObjectsOutput, error)

func (*S3Mock) GetBucketLocation added in v1.0.0

func (m *S3Mock) GetBucketLocation(input *s3.GetBucketLocationInput) (*s3.GetBucketLocationOutput, error)

func (*S3Mock) GetBucketLocationWithContext added in v1.16.0

func (m *S3Mock) GetBucketLocationWithContext(
	ctx aws.Context,
	input *s3.GetBucketLocationInput,
	options ...request.Option) (*s3.GetBucketLocationOutput, error)

func (*S3Mock) GetObject added in v1.0.0

func (m *S3Mock) GetObject(input *s3.GetObjectInput) (*s3.GetObjectOutput, error)

func (*S3Mock) GetObjectWithContext added in v1.6.0

func (m *S3Mock) GetObjectWithContext(ctx aws.Context, input *s3.GetObjectInput, options ...request.Option) (*s3.GetObjectOutput, error)

func (*S3Mock) HeadObject added in v1.16.0

func (m *S3Mock) HeadObject(i *s3.HeadObjectInput) (*s3.HeadObjectOutput, error)

func (*S3Mock) ListObjects added in v1.16.0

func (m *S3Mock) ListObjects(i *s3.ListObjectsInput) (*s3.ListObjectsOutput, error)

func (*S3Mock) ListObjectsV2Pages added in v1.3.0

func (m *S3Mock) ListObjectsV2Pages(input *s3.ListObjectsV2Input, f func(page *s3.ListObjectsV2Output, morePages bool) bool) error

func (*S3Mock) ListObjectsV2PagesWithContext added in v1.6.0

func (m *S3Mock) ListObjectsV2PagesWithContext(ctx aws.Context, input *s3.ListObjectsV2Input,
	f func(page *s3.ListObjectsV2Output, morePages bool) bool, options ...request.Option) error

func (*S3Mock) MaxRetries added in v1.13.0

func (m *S3Mock) MaxRetries() int

func (*S3Mock) SelectObjectContent added in v1.14.3

func (m *S3Mock) SelectObjectContent(input *s3.SelectObjectContentInput) (*s3.SelectObjectContentOutput, error)

func (*S3Mock) SelectObjectContentWithContext added in v1.14.3

func (m *S3Mock) SelectObjectContentWithContext(
	ctx aws.Context,
	input *s3.SelectObjectContentInput,
	options ...request.Option) (*s3.SelectObjectContentOutput, error)

type S3SelectStreamReaderMock added in v1.14.3

type S3SelectStreamReaderMock struct {
	s3.SelectObjectContentEventStreamReader
	mock.Mock
}

func (*S3SelectStreamReaderMock) Err added in v1.14.3

func (*S3SelectStreamReaderMock) Events added in v1.14.3

type S3UploaderMock added in v1.3.0

type S3UploaderMock struct {
	s3manageriface.UploaderAPI
	mock.Mock
}

func (*S3UploaderMock) Upload added in v1.3.0

type SnsMock added in v1.5.0

type SnsMock struct {
	snsiface.SNSAPI
	mock.Mock
}

func (*SnsMock) ConfirmSubscription added in v1.7.0

func (m *SnsMock) ConfirmSubscription(input *sns.ConfirmSubscriptionInput) (*sns.ConfirmSubscriptionOutput, error)

func (*SnsMock) Publish added in v1.5.0

func (m *SnsMock) Publish(input *sns.PublishInput) (*sns.PublishOutput, error)

func (*SnsMock) PublishWithContext added in v1.15.0

func (m *SnsMock) PublishWithContext(ctx context.Context, input *sns.PublishInput, options ...request.Option) (*sns.PublishOutput, error)

type SqsMock added in v1.1.0

type SqsMock struct {
	sqsiface.SQSAPI
	mock.Mock
}

func (*SqsMock) CreateQueue added in v1.6.0

func (m *SqsMock) CreateQueue(input *sqs.CreateQueueInput) (*sqs.CreateQueueOutput, error)

func (*SqsMock) DeleteMessageBatch added in v1.2.0

func (m *SqsMock) DeleteMessageBatch(input *sqs.DeleteMessageBatchInput) (*sqs.DeleteMessageBatchOutput, error)

func (*SqsMock) DeleteQueue added in v1.6.0

func (m *SqsMock) DeleteQueue(input *sqs.DeleteQueueInput) (*sqs.DeleteQueueOutput, error)

func (*SqsMock) GetQueueAttributes added in v1.2.0

func (m *SqsMock) GetQueueAttributes(input *sqs.GetQueueAttributesInput) (*sqs.GetQueueAttributesOutput, error)

func (*SqsMock) GetQueueAttributesWithContext added in v1.13.0

func (m *SqsMock) GetQueueAttributesWithContext(
	ctx aws.Context,
	input *sqs.GetQueueAttributesInput,
	options ...request.Option) (*sqs.GetQueueAttributesOutput, error)

func (*SqsMock) GetQueueUrl added in v1.15.0

func (m *SqsMock) GetQueueUrl(input *sqs.GetQueueUrlInput) (*sqs.GetQueueUrlOutput, error)

nolint (golint)

func (*SqsMock) ReceiveMessage added in v1.2.0

func (m *SqsMock) ReceiveMessage(input *sqs.ReceiveMessageInput) (*sqs.ReceiveMessageOutput, error)

func (*SqsMock) ReceiveMessageWithContext added in v1.13.0

func (m *SqsMock) ReceiveMessageWithContext(
	ctx aws.Context,
	input *sqs.ReceiveMessageInput,
	options ...request.Option) (*sqs.ReceiveMessageOutput, error)

func (*SqsMock) SendMessage added in v1.1.0

func (m *SqsMock) SendMessage(input *sqs.SendMessageInput) (*sqs.SendMessageOutput, error)

func (*SqsMock) SendMessageBatch added in v1.2.0

func (m *SqsMock) SendMessageBatch(input *sqs.SendMessageBatchInput) (*sqs.SendMessageBatchOutput, error)

func (*SqsMock) SendMessageWithContext added in v1.14.0

func (m *SqsMock) SendMessageWithContext(
	ctx context.Context,
	input *sqs.SendMessageInput,
	_ ...request.Option,
) (*sqs.SendMessageOutput, error)

func (*SqsMock) SetQueueAttributes added in v1.3.0

func (m *SqsMock) SetQueueAttributes(input *sqs.SetQueueAttributesInput) (*sqs.SetQueueAttributesOutput, error)

Jump to

Keyboard shortcuts

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