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) } }