Documentation
¶
Overview ¶
Package ez is a utility to create complex resource graphs for testing from a concise description by use of naming conventions and default values.
This package should only be used for testing. There is little error handling; most errors will result in a panic() to reduce the verbosity of the code.
Example ¶
ezg := Graph{ Nodes: []Node{ // Resource types are inferred automatically by naming convention. // Anything prefixed with "addr" is an Address. See *Factory.match // for the prefixes available. {Name: "addr"}, { Name: "fr", // Refs handles the complexity of referencing other resources. // FIeld refers to the name of the field in the structure. Refs: []Ref{ {Field: "IPAddress", To: "addr"}, {Field: "Target", To: "thp"}, }, // SetupFunc allows for customization of arbitrary resource. // This function is called after the automatic values have been // set on the resource. SetupFunc: func(x *compute.Address) { x.Description = "my address" }, }, {Name: "thp", Refs: []Ref{{Field: "UrlMap", To: "um"}}}, {Name: "um", Refs: []Ref{{Field: "DefaultService", To: "bs"}}}, { Name: "bs", Refs: []Ref{ // Zonal or regional resources should be referenced by "<scope>/<name>". {Field: "Backends.Group", To: "us-central1-a/neg"}, // Multiple references are expressed by multiple entries to // the same Field. {Field: "Backends.Group", To: "us-central1-b/neg"}, {Field: "Healthchecks", To: "hc"}, }, }, {Name: "hc"}, // Note we have two NEGs with the same name but different scopes. {Name: "neg", Zone: "us-central1-a"}, {Name: "neg", Zone: "us-central1-b"}, }, } // Build the graph for use in a test. ezg.Builder().MustBuild()
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Graph ¶
type Graph struct { // Nodes in the Graph. Nodes []Node // Project to use by default if not specified in the Node. Project string // Options to use by default in the Graph and Nodes. Options GraphOption // contains filtered or unexported fields }
Graph is an easy way to build resource Graphs. This is intended for static testing case construction. Errors are handled by panic().
type GraphOption ¶
type GraphOption int
GraphOption are flags controlling the state of the Graphs. Options should be joined via a bitwise OR "|".
const ( // PanicOnAccessErr causes panic() if Accces() returns an error. Otherwise, // the error is ignored. PanicOnAccessErr GraphOption = 1 << iota )
type Node ¶
type Node struct { // Name of the resource/node. Name string // Refs to other resources. Refs []Ref // Options for this node. Options NodeOption // SetupFunc will be called to initialize the contents of the Node. The type // of this func should match the type of MutableResource.Access(). For // example, for compute.Address, the signature of this function is: // func(*compute.Address). SetupFunc any // Region if applicable. Region string // Zone if applicable. Zone string // Project will override the Project in Graph. Project string }
Node in the graph. This is intended for static testing case construction. Errors are handled by panic().
type NodeOption ¶
type NodeOption int
NodeOption are flags controlling the state of the nodes. Options should be joined via a bitwise OR "|".
const ( // External ownership. External NodeOption = 1 << iota // Managed ownership. Managed // Exists state (default). Exists // DoesNotExist state. DoesNotExist )