It carried the thing it was going to run; it now carries the thing that makes it. One artifact either way — but a mesh raised this way holds a control plane it built from a repository and a commit it can name, and can therefore build again. A mesh handed a finished image could not, and had no way to find that out until somebody needed it to. A build step sits between load and bundle, because the bundle must name an image and that image no longer arrives finished. Everything after it is unchanged: a locally built image is named by the digest of its own configuration, which is exactly what the carried one was named by. Refused in preflight when nothing says what to build, so a run that cannot finish says so before it has changed anything.
42 lines
1.5 KiB
Go
42 lines
1.5 KiB
Go
package bootstrap
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// An installer that carries a builder and was told nothing refuses, and says what is missing.
|
|
//
|
|
// **Exercised rather than assumed.** This is the refusal that stands between a person and a
|
|
// machine left holding a store, a broker and no control plane — the failure the whole preflight
|
|
// exists to prevent — and a refusal nothing tests is a refusal nobody has read.
|
|
func TestAnInstallerWithNothingToBuildRefuses(t *testing.T) {
|
|
err := Source{}.Check()
|
|
if err == nil {
|
|
t.Fatal("a source naming no repository was accepted; nothing would have been built")
|
|
}
|
|
for _, want := range []string{"--source", "--source-ref"} {
|
|
if !strings.Contains(err.Error(), want) {
|
|
t.Errorf("the refusal does not name %s, so it does not say how to fix it: %v", want, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
// A repository without a commit refuses too, because a branch is somebody else's moving target.
|
|
func TestABranchIsNotACommit(t *testing.T) {
|
|
err := Source{Repository: "https://example.invalid/mesh-control.git"}.Check()
|
|
if err == nil {
|
|
t.Fatal("a source with no ref was accepted; genesis would have built whatever a branch pointed at")
|
|
}
|
|
if !strings.Contains(err.Error(), "--source-ref") {
|
|
t.Errorf("the refusal does not name the flag that fixes it: %v", err)
|
|
}
|
|
}
|
|
|
|
// And a repository with a commit is enough.
|
|
func TestARepositoryAndACommitIsEnough(t *testing.T) {
|
|
if err := (Source{Repository: "https://example.invalid/mesh-control.git", Ref: "a1b2c3d4"}).Check(); err != nil {
|
|
t.Fatalf("a repository and a commit were refused: %v", err)
|
|
}
|
|
}
|