gen

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package gen contains and utils for working with generators.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareBytes added in v0.5.0

func CompareBytes(t *testing.T, ex, out []byte)

CompareBytes is a testing utility for comparing generator outputs.

func WithContext

func WithContext(ctx context.Context, gCtx GeneratorContext) context.Context

WithContext returns a prepared context.Context with the given GeneratorContext.

Types

type Generator

type Generator interface {
	// Generate handles converting a GraphQL Document to scaffolded source code.
	Generate(ctx context.Context, doc *ast.Document, opts map[string]interface{}) error
}

Generator provides a simple API for creating a code generator for any language desired.

type GeneratorContext

type GeneratorContext interface {
	// Open opens a file in the GeneratorContext (i.e. directory).
	Open(filename string) (io.WriteCloser, error)
}

GeneratorContext represents the directory to which the Generator is to write to.

func Context

func Context(ctx context.Context) GeneratorContext

Context returns the generator context.

type GeneratorError

type GeneratorError struct {
	// DocName is the document being worked on when error was encountered.
	DocName string

	// GenName is the generator name which encountered a problem.
	GenName string

	// Msg is any message the generator wants to provide back to the caller.
	Msg string
}

GeneratorError represents an error from a generator.

func (GeneratorError) Error

func (e GeneratorError) Error() string

type MockGenerator

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

MockGenerator is a mock of Generator interface

func NewMockGenerator

func NewMockGenerator(ctrl *gomock.Controller) *MockGenerator

NewMockGenerator creates a new mock instance

func (*MockGenerator) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockGenerator) Generate

func (m *MockGenerator) Generate(arg0 context.Context, arg1 *ast.Document, arg2 map[string]interface{}) error

Generate mocks base method

type MockGeneratorMockRecorder

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

MockGeneratorMockRecorder is the mock recorder for MockGenerator

func (*MockGeneratorMockRecorder) Generate

func (mr *MockGeneratorMockRecorder) Generate(arg0, arg1, arg2 interface{}) *gomock.Call

Generate indicates an expected call of Generate

type TestCtx

type TestCtx struct {
	io.Writer
}

TestCtx is a noop closer, which wraps an io.Writer and only meant to be used for tests.

func (TestCtx) Close

func (ctx TestCtx) Close() error

Close always returns nil.

func (TestCtx) Open

func (ctx TestCtx) Open(filename string) (io.WriteCloser, error)

Open returns the underlying io.Writer.

Jump to

Keyboard shortcuts

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