This change adds a handful of property binding tests. It also fixes: * AsName should assert IsName. * Enumerate properties stably, so that it is deterministic. * Do not issue errors about unrecognized properties for the special `mu/extension` type. It's entire purpose in life is to offer an entirely custom set of properties, which the provider is meant to validate. * Default to an empty map if properties are missing. * Add a "/" to the end of the namespace from the workspace, if present. And rearranges some code: * Rename the LiteralX types to XLiteral; e.g., StringLiteral instead of LiteralString. I kept typing XLiteral erroneously. * Eliminate the Mu prefix on all of the predefined type and service functions and types. It's superfluous and reads nicer this way. * Swap the order of "expected" vs. "got" in the error message about incorrect property types. It used to say "got %v, expected %v"; I personally find that it is more helpful if it says "expected %v, got %v". YMMV.
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
// Copyright 2016 Marapongo, Inc. All rights reserved.
|
|
|
|
package compiler
|
|
|
|
import (
|
|
"github.com/marapongo/mu/pkg/ast"
|
|
"github.com/marapongo/mu/pkg/compiler/backends"
|
|
"github.com/marapongo/mu/pkg/util"
|
|
)
|
|
|
|
// Context holds all state available to any templates or code evaluated at compile-time.
|
|
type Context struct {
|
|
Cluster *ast.Cluster // the cluster that we will deploy to.
|
|
Arch backends.Arch // the target cloud architecture.
|
|
Properties ast.PropertyBag // properties supplied at stack construction time.
|
|
}
|
|
|
|
// NewContext returns a new, empty context.
|
|
func NewContext() *Context {
|
|
return &Context{
|
|
Properties: make(ast.PropertyBag),
|
|
}
|
|
}
|
|
|
|
// WithClusterArch returns a clone of this Context with the given cluster and architecture attached to it.
|
|
func (c *Context) WithClusterArch(cl *ast.Cluster, a backends.Arch) *Context {
|
|
util.Assert(cl != nil)
|
|
return &Context{
|
|
Cluster: cl,
|
|
Arch: a,
|
|
Properties: c.Properties,
|
|
}
|
|
}
|
|
|
|
// WithProps returns a clone of this Context with the given properties attached to it.
|
|
func (c *Context) WithProps(props ast.PropertyBag) *Context {
|
|
if props == nil {
|
|
props = make(ast.PropertyBag)
|
|
}
|
|
return &Context{
|
|
Cluster: c.Cluster,
|
|
Arch: c.Arch,
|
|
Properties: props,
|
|
}
|
|
}
|