This change adds support for Workspaces, a convenient way of sharing settings among many Stacks, like default cluster targets, configuration settings, and the like, which are not meant to be distributed as part of the Stack itself. The following things are included in this checkin: * At workspace initialization time, detect and parse the .mu/workspace.yaml file. This is pretty rudimentary right now and contains just the default cluster targets. The results are stored in a new ast.Workspace type. * Rename "target" to "cluster". This impacts many things, including ast.Target being changed to ast.Cluster, and all related fields, the command line --target being changed to --cluster, various internal helper functions, and so on. This helps to reinforce the desired mental model. * Eliminate the ast.Metadata type. Instead, the metadata moves directly onto the Stack. This reflects the decision to make Stacks "the thing" that is distributed, versioned, and is the granularity of dependency. * During cluster targeting, add the workspace settings into the probing logic. We still search in the same order: CLI > Stack > Workspace.
106 lines
3.6 KiB
Go
106 lines
3.6 KiB
Go
// Copyright 2016 Marapongo, Inc. All rights reserved.
|
|
|
|
package compiler
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/marapongo/mu/pkg/diag"
|
|
"github.com/marapongo/mu/pkg/errors"
|
|
)
|
|
|
|
func TestBadMissingStackName(t *testing.T) {
|
|
sink := buildNoCodegen("testdata", "parsetree", "bad__missing_stack_name")
|
|
|
|
// Check that the compiler complained about a missing Stack name.
|
|
d := errors.MissingStackName
|
|
assert.Equal(t, 1, sink.Errors(), "expected a single error")
|
|
assert.Equal(t,
|
|
fmt.Sprintf("%v: %v%v: %v: %v\n",
|
|
diag.DefaultSinkErrorPrefix, diag.DefaultSinkIDPrefix, d.ID, "Mu.yaml", d.Message),
|
|
sink.ErrorMsgs()[0])
|
|
}
|
|
|
|
func TestBadStackSemVer1(t *testing.T) {
|
|
sink := buildNoCodegen("testdata", "parsetree", "bad__stack_semver__1")
|
|
|
|
// Check that the compiler complained about an illegal semantic version.
|
|
d := errors.IllegalStackSemVer
|
|
assert.Equal(t, 1, sink.Errors(), "expected a single error")
|
|
assert.Equal(t,
|
|
fmt.Sprintf("%v: %v%v: %v: %v\n",
|
|
diag.DefaultSinkErrorPrefix, diag.DefaultSinkIDPrefix, d.ID, "Mu.yaml",
|
|
fmt.Sprintf(d.Message, "badbadbad")),
|
|
sink.ErrorMsgs()[0])
|
|
}
|
|
|
|
func TestBadStackSemVer2(t *testing.T) {
|
|
sink := buildNoCodegen("testdata", "parsetree", "bad__stack_semver__2")
|
|
|
|
// Check that the compiler complained about an illegal semantic version.
|
|
d := errors.IllegalStackSemVer
|
|
assert.Equal(t, 1, sink.Errors(), "expected a single error")
|
|
assert.Equal(t,
|
|
fmt.Sprintf("%v: %v%v: %v: %v\n",
|
|
diag.DefaultSinkErrorPrefix, diag.DefaultSinkIDPrefix, d.ID, "Mu.yaml",
|
|
fmt.Sprintf(d.Message, ">1.0.0")),
|
|
sink.ErrorMsgs()[0])
|
|
}
|
|
|
|
func TestBadDepSemVer1(t *testing.T) {
|
|
sink := buildNoCodegen("testdata", "parsetree", "bad__dep_semver__1")
|
|
|
|
// Check that the compiler complained about an illegal semantic version.
|
|
d := errors.IllegalDependencySemVer
|
|
assert.Equal(t, 1, sink.Errors(), "expected a single error")
|
|
assert.Equal(t,
|
|
fmt.Sprintf("%v: %v%v: %v: %v\n",
|
|
diag.DefaultSinkErrorPrefix, diag.DefaultSinkIDPrefix, d.ID, "Mu.yaml",
|
|
fmt.Sprintf(d.Message, "dep1", "badbadbad")),
|
|
sink.ErrorMsgs()[0])
|
|
}
|
|
|
|
func TestBadDepSemVer2(t *testing.T) {
|
|
sink := buildNoCodegen("testdata", "parsetree", "bad__dep_semver__2")
|
|
|
|
// Check that the compiler complained about an illegal semantic version.
|
|
d := errors.IllegalDependencySemVer
|
|
assert.Equal(t, 1, sink.Errors(), "expected a single error")
|
|
assert.Equal(t,
|
|
fmt.Sprintf("%v: %v%v: %v: %v\n",
|
|
diag.DefaultSinkErrorPrefix, diag.DefaultSinkIDPrefix, d.ID, "Mu.yaml",
|
|
fmt.Sprintf(d.Message, "dep3", "badbadbad")),
|
|
sink.ErrorMsgs()[0])
|
|
}
|
|
|
|
func TestBadDepSemVer3(t *testing.T) {
|
|
sink := buildNoCodegen("testdata", "parsetree", "bad__dep_semver__3")
|
|
|
|
// Check that the compiler complained about an illegal semantic version.
|
|
d := errors.IllegalDependencySemVer
|
|
assert.Equal(t, 4, sink.Errors(), "expected an error for each bad semver")
|
|
assert.Equal(t,
|
|
fmt.Sprintf("%v: %v%v: %v: %v\n",
|
|
diag.DefaultSinkErrorPrefix, diag.DefaultSinkIDPrefix, d.ID, "Mu.yaml",
|
|
fmt.Sprintf(d.Message, "dep1", "bad1")),
|
|
sink.ErrorMsgs()[0])
|
|
assert.Equal(t,
|
|
fmt.Sprintf("%v: %v%v: %v: %v\n",
|
|
diag.DefaultSinkErrorPrefix, diag.DefaultSinkIDPrefix, d.ID, "Mu.yaml",
|
|
fmt.Sprintf(d.Message, "dep2", "0.0")),
|
|
sink.ErrorMsgs()[1])
|
|
assert.Equal(t,
|
|
fmt.Sprintf("%v: %v%v: %v: %v\n",
|
|
diag.DefaultSinkErrorPrefix, diag.DefaultSinkIDPrefix, d.ID, "Mu.yaml",
|
|
fmt.Sprintf(d.Message, "dep3", "bad3")),
|
|
sink.ErrorMsgs()[2])
|
|
assert.Equal(t,
|
|
fmt.Sprintf("%v: %v%v: %v: %v\n",
|
|
diag.DefaultSinkErrorPrefix, diag.DefaultSinkIDPrefix, d.ID, "Mu.yaml",
|
|
fmt.Sprintf(d.Message, "dep4", "0.6.bad.ness.1")),
|
|
sink.ErrorMsgs()[3])
|
|
}
|