package
0.4.1
Repository: https://github.com/goplugin/plugin-common.git
Documentation: pkg.go.dev

# 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] ...

# Packages

No description provided by the author
No description provided by the author

# Functions

No description provided by the author
No description provided by the author
No description provided by the author

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
CapabilitiesRegistry.
No description provided by the author
No description provided by the author

# Structs

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`.
GRPCScaffold is a test scaffold for grpc tests.
No description provided by the author
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.

# Interfaces

No description provided by the author

# Type aliases

No description provided by the author
SetupGRPCClient is a function that sets up a grpc client with a given broker and connection analogous to SetupGRPCServer.
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.