test

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 21 Imported by: 0

README

This package contains test implementations for all the components that compose OCR2 LOOPPs. The existing of this directory is partially an intermediate term workaround for lack of packages within loop/internal the https://smartcontract-it.atlassian.net/browse/BCF-3039. When that issue is addressed, we can move these test implementations into specific test packages for each packaged component.

With all that said, the directory layout is intended to mirror the natural interfaces composition of libocr:

  • ocr2: contains static test implementations for reuseable reporting plugin, factory, and plugin provider
  • core: represents core-node provided resources used to in calls to core node api(s) eg pipeline_runner, keystore, etc
  • types: type definitions used in through tests

Every test implementation follows the pattern wrapping an interface and provider one or more funcs to compare to another instance of the interface. Every package attempts to share exposed the bare minimum surface area to avoid entanglement with logically separated tests and domains.

In practice this is accomplished by exporting a static implementation and an interface that the implementation satisfies. The interface is used by other packages to declaration dependencies and the implementation is used in the test implementation of those other packaged

Example

go
package types

type Evaluator[T any] interface {
     // run methods of other, returns first error or error if
    // result of method invocation does not match expected value
    Evaluate(ctx context.Context, other T) error
}

package x

import ( testtypes "github.com/goplugin/plugin-common/pkg/loop/internal/test/types" "github.com/goplugin/plugin-common/pkg/types" )

var FooEvaluator = staticFoo{ expectedStr = "a" expectedInt = 1 }

type staticFoo struct { types.Foo // the interface to be tested, used to compose a loop expectedStr string expectedInt int ... }

var _ testtypes.Evaulator[Foo] = staticFoo var _ types.Foo = staticFoo

func (f Foo) Evaluate(ctx context.Context, other Foo) { // test implementation of types.Foo interface s, err := other.GetStr() if err ! = nil { return fmt.Errorf("other failed to get str: %w", err) } if s != f.expectedStr { return fmt.Errorf(" expected str %s got %s", s.expectedStr, s) } ... }

// implements types.Foo func (f Foo) GetStr() (string, error) { return f.expectedStr, nil } ...


package y

import ( testx "github.com/goplugin/plugin-common/pkg/loop/internal/test/x" testtypes "github.com/goplugin/plugin-common/pkg/loop/internal/test/types" "github.com/goplugin/plugin-common/pkg/types" )

var BarEvaluator = staticBar{ expectedFoo = x_test.FooImpl expectedBytes = []bytes{1:1} }

type staticBar struct { types.Bar // test implementation of Bar interface expectedFoo types_test[types.Foo] expectedInt int ... }

// BarEvaluation implement [types.Bar] and [types_test.Evaluator[types.Bar]] to be used in tests var _ BarEvaluator = staticBar { expectedFoo x_test.FooEvaluator expectedInt = 7 ... }

var _ testtypes[types.Bar] = staticBar

// implement types.Bar ... // implement types_test.Evaluator[types.Bar] ...

Documentation

Index

Constants

View Source
const (
	PANIC = iota
	FATAL
	CRITICAL
	ERROR
	INFO
	WARN
	DEBUG
)
View Source
const ConfigTOML = `[Foo]
Bar = "Baz"
`
View Source
const PluginLoggerTestName = "logger-test"

Variables

View Source
var (

	//CapabilitiesRegistry
	GetID          = "get-id"
	GetTriggerID   = "get-trigger-id"
	GetActionID    = "get-action-id"
	GetConsensusID = "get-consensus-id"
	GetTargetID    = "get-target-id"
	CapabilityInfo = capabilities.CapabilityInfo{
		ID:             "capability-info-id@1.0.0",
		CapabilityType: capabilities.CapabilityTypeAction,
		Description:    "capability-info-description",
	}
)

Functions

func PluginLoggerTestHandshakeConfig

func PluginLoggerTestHandshakeConfig() plugin.HandshakeConfig

func PluginTest

func PluginTest[TB testing.TB, I any](tb TB, name string, p plugin.Plugin, testFn func(TB, I))

Types

type Client

type Client interface {
	io.Closer
	goplugin.GRPCClientConn
}

type GRPCPluginLoggerTest

type GRPCPluginLoggerTest struct {
	plugin.NetRPCUnsupportedPlugin
	logger.SugaredLogger
	ErrorType int
}

NOTE: This is part of the test package because it needs to be imported by the test binary at `./internal/test/cmd` as well as the test at `./pkg/loop/logger_loop_test.go`

func (*GRPCPluginLoggerTest) ClientConfig

func (g *GRPCPluginLoggerTest) ClientConfig() *plugin.ClientConfig

func (*GRPCPluginLoggerTest) GRPCClient

func (g *GRPCPluginLoggerTest) GRPCClient(context.Context, *plugin.GRPCBroker, *grpc.ClientConn) (interface{}, error)

func (*GRPCPluginLoggerTest) GRPCServer

func (g *GRPCPluginLoggerTest) GRPCServer(*plugin.GRPCBroker, *grpc.Server) (err error)

type GRPCScaffold

type GRPCScaffold[C Client, S Server] struct {
	// contains filtered or unexported fields
}

GRPCScaffold is a test scaffold for grpc tests

func NewGRPCScaffold

func NewGRPCScaffold[T Client, S any](t *testing.T, serverFn SetupGRPCServer[S], clientFn SetupGRPCClient[T]) *GRPCScaffold[T, S]

func (*GRPCScaffold[T, S]) Client

func (t *GRPCScaffold[T, S]) Client() T

func (*GRPCScaffold[T, S]) Close

func (t *GRPCScaffold[T, S]) Close()

Caller must either call Close() on the returned GRPCScaffold or manually close the Client. some implementations in our suite of LOOPPs release server resources on client.Close() and in that case, the caller should call Client().Close() and test that the server resources are released

func (*GRPCScaffold[T, S]) Server

func (t *GRPCScaffold[T, S]) Server() S

type HelperProcessCommand

type HelperProcessCommand struct {
	Limit           int
	CommandLocation string
	Command         string
	StaticChecks    bool
	ThrowErrorType  int
}

func (HelperProcessCommand) New

func (h HelperProcessCommand) New() *exec.Cmd

type MockDep

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

MockDep is a mock dependency that can be used to test that a grpc client closes its dependencies to be used in tests that require a grpc client to close its dependencies

func (*MockDep) Close

func (m *MockDep) Close() error

func (*MockDep) IsClosed

func (m *MockDep) IsClosed() bool

type Server

type Server any

type SetupGRPCClient

type SetupGRPCClient[T Client] func(b *loopnet.BrokerExt, conn grpc.ClientConnInterface) T

SetupGRPCClient is a function that sets up a grpc client with a given broker and connection analogous to SetupGRPCServer. Typically it is implemented as a light wrapper around the grpc client constructor

type SetupGRPCServer

type SetupGRPCServer[S any] func(t *testing.T, s *grpc.Server, b *loopnet.BrokerExt) S

SetupGRPCServer is a function that sets up a grpc server with a given broker typical and expected usage is to instantiate a grpc server implementation with a static test interface implementation and then register that grpc server e.g. ```

func setupCCIPCommitProviderGRPCServer(t *testing.T, s *grpc.Server, b *loopnet.BrokerExt) *grpc.Server {
  commitProvider := ccip.NewCommitProviderServer(CommitProvider, b)
  ccippb.RegisterCommitCustomHandlersServer(s, commitProvider)
  return s
}

```

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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