opa: github.com/open-policy-agent/opa/internal/storage/mock Index | Files

package mock

import "github.com/open-policy-agent/opa/internal/storage/mock"

Package mock defines a fake storage implementation for use in testing.

Index

Package Files

mock.go

type ReadCall Uses

type ReadCall struct {
    Transaction *Transaction
    Path        storage.Path
    Error       error
    Safe        bool
}

ReadCall captures the parameters for a Read call

type Store Uses

type Store struct {
    Transactions []*Transaction
    Reads        []*ReadCall
    Writes       []*WriteCall
    // contains filtered or unexported fields
}

Store is a mock storage.Store implementation for use in testing.

func New Uses

func New() *Store

New creates a new mock Store

func NewWithData Uses

func NewWithData(data map[string]interface{}) *Store

NewWithData creates a store with some initial data

func (*Store) Abort Uses

func (s *Store) Abort(ctx context.Context, txn storage.Transaction)

Abort will abort the underlying transaction while also updating the mock Transaction

func (*Store) AssertValid Uses

func (s *Store) AssertValid(t *testing.T)

AssertValid will raise an error with the provided testing.T if there are any errors on the store.

func (*Store) Build Uses

func (s *Store) Build(ctx context.Context, txn storage.Transaction, ref ast.Ref) (storage.Index, error)

Build just shims the call to the underlying inmem store

func (*Store) Commit Uses

func (s *Store) Commit(ctx context.Context, txn storage.Transaction) error

Commit will commit the underlying transaction while also updating the mock Transaction

func (*Store) DeletePolicy Uses

func (s *Store) DeletePolicy(ctx context.Context, txn storage.Transaction, name string) error

DeletePolicy just shims the call to the underlying inmem store

func (*Store) Errors Uses

func (s *Store) Errors() []error

Errors returns a list of errors for each invalid state found. If any Transactions are invalid or reads/writes were unsafe an error will be returned for each problem.

func (*Store) GetPolicy Uses

func (s *Store) GetPolicy(ctx context.Context, txn storage.Transaction, name string) ([]byte, error)

GetPolicy just shims the call to the underlying inmem store

func (*Store) GetTransaction Uses

func (s *Store) GetTransaction(id uint64) *Transaction

GetTransaction will a transaction with a specific ID that was associated with this Store.

func (*Store) ListPolicies Uses

func (s *Store) ListPolicies(ctx context.Context, txn storage.Transaction) ([]string, error)

ListPolicies just shims the call to the underlying inmem store

func (*Store) NewTransaction Uses

func (s *Store) NewTransaction(ctx context.Context, params ...storage.TransactionParams) (storage.Transaction, error)

NewTransaction will create a new transaction on the underlying inmem store but wraps it with a mock Transaction. These are then tracked on the store.

func (*Store) Read Uses

func (s *Store) Read(ctx context.Context, txn storage.Transaction, path storage.Path) (interface{}, error)

Read will make a read from the underlying inmem store and add a new entry to the mock store Reads list. If there is an error are the read is unsafe it will be noted in the ReadCall.

func (*Store) Register Uses

func (s *Store) Register(ctx context.Context, txn storage.Transaction, config storage.TriggerConfig) (storage.TriggerHandle, error)

Register just shims the call to the underlying inmem store

func (*Store) Reset Uses

func (s *Store) Reset()

Reset the store

func (*Store) UpsertPolicy Uses

func (s *Store) UpsertPolicy(ctx context.Context, txn storage.Transaction, name string, policy []byte) error

UpsertPolicy just shims the call to the underlying inmem store

func (*Store) Write Uses

func (s *Store) Write(ctx context.Context, txn storage.Transaction, op storage.PatchOp, path storage.Path, value interface{}) error

Write will make a read from the underlying inmem store and add a new entry to the mock store Writes list. If there is an error are the write is unsafe it will be noted in the WriteCall.

type Transaction Uses

type Transaction struct {
    Committed int
    Aborted   int
    // contains filtered or unexported fields
}

Transaction is a mock storage.Transaction implementation for use in testing. It uses an internal storage.Transaction pointer with some added functionality.

func (*Transaction) ID Uses

func (t *Transaction) ID() uint64

ID returns the underlying transaction ID

func (*Transaction) Validate Uses

func (t *Transaction) Validate() error

Validate returns an error if the transaction is in an invalid state

type WriteCall Uses

type WriteCall struct {
    Transaction *Transaction
    Op          storage.PatchOp
    Path        storage.Path
    Error       error
    Safe        bool
}

WriteCall captures the parameters for a write call

Package mock imports 6 packages (graph). Updated 2019-10-13. Refresh now. Tools for package owners.