2016-11-16 04:16:02 +01:00
|
|
|
// Copyright 2016 Marapongo, Inc. All rights reserved.
|
|
|
|
|
|
|
|
package compiler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2016-11-18 21:40:15 +01:00
|
|
|
"github.com/marapongo/mu/pkg/compiler/backends"
|
|
|
|
"github.com/marapongo/mu/pkg/compiler/backends/clouds"
|
2016-11-16 04:16:02 +01:00
|
|
|
"github.com/marapongo/mu/pkg/diag"
|
|
|
|
"github.com/marapongo/mu/pkg/errors"
|
|
|
|
)
|
|
|
|
|
2016-11-16 19:02:34 +01:00
|
|
|
func TestBadMissingMufile(t *testing.T) {
|
2016-11-17 22:08:20 +01:00
|
|
|
sink := buildNoCodegen("testdata", "compiler", "bad__missing_mufile")
|
2016-11-16 04:16:02 +01:00
|
|
|
|
2016-11-16 19:02:34 +01:00
|
|
|
// Check that the compiler complained about a missing Mufile.
|
2016-11-16 04:16:02 +01:00
|
|
|
d := errors.MissingMufile
|
2016-11-17 03:51:14 +01:00
|
|
|
assert.Equal(t, 1, sink.Errors(), "expected a single error")
|
2016-11-16 17:19:26 +01:00
|
|
|
assert.Equal(t,
|
|
|
|
fmt.Sprintf("%v: %v%v: %v\n",
|
|
|
|
diag.DefaultSinkErrorPrefix, diag.DefaultSinkIDPrefix, d.ID, fmt.Sprintf(d.Message, sink.Pwd)),
|
|
|
|
sink.ErrorMsgs()[0])
|
|
|
|
}
|
|
|
|
|
2016-11-16 19:02:34 +01:00
|
|
|
func TestBadMufileCasing(t *testing.T) {
|
2016-11-17 22:08:20 +01:00
|
|
|
sink := buildNoCodegen("testdata", "compiler", "bad__mufile_casing")
|
2016-11-16 17:19:26 +01:00
|
|
|
|
2016-11-16 19:02:34 +01:00
|
|
|
// Check that the compiler warned about a bad Mufile casing (mu.yaml).
|
2016-11-16 17:19:26 +01:00
|
|
|
d := errors.WarnIllegalMufileCasing
|
2016-11-17 03:51:14 +01:00
|
|
|
assert.Equal(t, 1, sink.Warnings(), "expected a single warning")
|
2016-11-16 17:19:26 +01:00
|
|
|
assert.Equal(t,
|
|
|
|
fmt.Sprintf("%v: %v%v: %v: %v\n",
|
|
|
|
diag.DefaultSinkWarningPrefix, diag.DefaultSinkIDPrefix, d.ID, "mu.yaml", d.Message),
|
|
|
|
sink.WarningMsgs()[0])
|
|
|
|
}
|
|
|
|
|
2016-11-16 19:02:34 +01:00
|
|
|
func TestBadMufileExt1(t *testing.T) {
|
2016-11-17 22:08:20 +01:00
|
|
|
sink := buildNoCodegen("testdata", "compiler", "bad__mufile_ext__1")
|
2016-11-16 17:19:26 +01:00
|
|
|
|
2016-11-16 19:02:34 +01:00
|
|
|
// Check that the compiler warned about a bad Mufile extension (none).
|
2016-11-16 17:19:26 +01:00
|
|
|
d := errors.WarnIllegalMufileExt
|
2016-11-17 03:51:14 +01:00
|
|
|
assert.Equal(t, 1, sink.Warnings(), "expected a single warning")
|
2016-11-16 17:19:26 +01:00
|
|
|
assert.Equal(t,
|
|
|
|
fmt.Sprintf("%v: %v%v: %v: %v\n",
|
|
|
|
diag.DefaultSinkWarningPrefix, diag.DefaultSinkIDPrefix, d.ID, "Mu", fmt.Sprintf(d.Message, "")),
|
|
|
|
sink.WarningMsgs()[0])
|
|
|
|
}
|
|
|
|
|
2016-11-16 19:02:34 +01:00
|
|
|
func TestBadMufileExt2(t *testing.T) {
|
2016-11-17 22:08:20 +01:00
|
|
|
sink := buildNoCodegen("testdata", "compiler", "bad__mufile_ext__2")
|
2016-11-16 17:19:26 +01:00
|
|
|
|
2016-11-16 19:02:34 +01:00
|
|
|
// Check that the compiler warned about a bad Mufile extension (".txt").
|
2016-11-16 17:19:26 +01:00
|
|
|
d := errors.WarnIllegalMufileExt
|
2016-11-17 03:51:14 +01:00
|
|
|
assert.Equal(t, 1, sink.Warnings(), "expected a single warning")
|
2016-11-16 17:19:26 +01:00
|
|
|
assert.Equal(t,
|
|
|
|
fmt.Sprintf("%v: %v%v: %v: %v\n",
|
|
|
|
diag.DefaultSinkWarningPrefix, diag.DefaultSinkIDPrefix, d.ID, "Mu.txt", fmt.Sprintf(d.Message, ".txt")),
|
|
|
|
sink.WarningMsgs()[0])
|
2016-11-16 04:16:02 +01:00
|
|
|
}
|
2016-11-17 22:08:20 +01:00
|
|
|
|
|
|
|
func TestMissingTarget(t *testing.T) {
|
2016-11-19 02:30:32 +01:00
|
|
|
mufile := []byte("name: notarget\n" +
|
|
|
|
"abstract: true\n")
|
2016-11-17 22:08:20 +01:00
|
|
|
|
|
|
|
// Check that the compiler issued an error due to missing cloud targets.
|
2016-11-18 00:13:36 +01:00
|
|
|
sink := buildFile(Options{}, mufile, ".yaml")
|
2016-11-17 22:08:20 +01:00
|
|
|
d := errors.MissingTarget
|
|
|
|
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])
|
|
|
|
|
|
|
|
// Now check that this same project compiles fine if we manually specify an architecture.
|
2016-11-18 00:13:36 +01:00
|
|
|
sink = buildFile(Options{
|
2016-11-18 21:40:15 +01:00
|
|
|
Arch: backends.Arch{
|
2016-11-17 22:08:20 +01:00
|
|
|
Cloud: clouds.AWSArch,
|
|
|
|
},
|
2016-11-18 00:13:36 +01:00
|
|
|
}, mufile, ".yaml")
|
2016-11-17 22:08:20 +01:00
|
|
|
assert.Equal(t, 0, sink.Errors(), "expected no compilation errors")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUnrecognizedCloud(t *testing.T) {
|
|
|
|
mufile := []byte("name: notarget\n" +
|
2016-11-19 02:30:32 +01:00
|
|
|
"abstract: true\n" +
|
Support Workspaces
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.
2016-11-22 19:41:07 +01:00
|
|
|
"clusters:\n" +
|
2016-11-17 22:08:20 +01:00
|
|
|
" prod:\n" +
|
|
|
|
" default: true\n" +
|
|
|
|
" cloud: badcloud\n")
|
|
|
|
// Check that the compiler issued an error due to an unrecognized cloud.
|
2016-11-18 00:13:36 +01:00
|
|
|
sink := buildFile(Options{}, mufile, ".yaml")
|
2016-11-17 22:08:20 +01:00
|
|
|
d := errors.UnrecognizedCloudArch
|
|
|
|
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, "badcloud")),
|
|
|
|
sink.ErrorMsgs()[0])
|
|
|
|
}
|