- migrate, migrate:rollback and deferred:purge gain --pretend and --force; they and queue:clear confirm only in production on an interactive terminal, so deploys over SSH proceed as before - result lines: Applied N migrations, Rolled back <id> of <plugin>, Cleared N jobs from <queue> - --json for migrate:status, key:generate, route:list, admin:token:create, admin:token:list, admin:token:scopes and websockets:health; -q keeps the key and the token - hints for an empty DSN, an unreachable database, an invalid app.key, a missing uploads bucket and an application binary run below its root - flare and websockets:health return bonfire.Reported after printing - long help and examples for every application command, greeter:hello and blog:publish; cmd/summer TestCommandsDocumented fails on any gap
58 lines
1.8 KiB
Go
58 lines
1.8 KiB
Go
package bonfire
|
|
|
|
import (
|
|
"bytes"
|
|
"errors"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestWrongDirectoryHintSmoke: an application binary failing below its
|
|
// application root (no config/ here, summer.yaml in a parent) gets the
|
|
// "cd <rel>; bin/<name> <args>" hint; summer, a directory with config/ and
|
|
// a usage error do not.
|
|
func TestWrongDirectoryHintSmoke(t *testing.T) {
|
|
root := t.TempDir()
|
|
if err := os.WriteFile(filepath.Join(root, "summer.yaml"), []byte("binary: acme\n"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sub := filepath.Join(root, "plugins", "acme")
|
|
if err := os.MkdirAll(sub, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.MkdirAll(filepath.Join(root, "config"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
fail := errors.New("lagoon: database.dsn is empty")
|
|
|
|
got := wrongDirectory("acme", fail, []string{"migrate", "--plugin", "acme blog"}, sub)
|
|
var hint *HintError
|
|
if !errors.As(got, &hint) || hint.Explanation != wrongDirectoryExplanation ||
|
|
hint.Try != "cd ../..; {bin} migrate --plugin 'acme blog'" || !errors.Is(got, fail) {
|
|
t.Fatalf("hint = %#v", got)
|
|
}
|
|
var buf bytes.Buffer
|
|
RenderError(&buf, "acme", got, Globals{Color: ColorNever})
|
|
if !strings.Contains(buf.String(), "cd ../..; bin/acme migrate --plugin 'acme blog'") {
|
|
t.Fatalf("rendered block lacks the Try line:\n%s", buf.String())
|
|
}
|
|
|
|
for name, tc := range map[string]struct {
|
|
name string
|
|
err error
|
|
dir string
|
|
}{
|
|
"summer": {"summer", fail, sub},
|
|
"app root": {"acme", fail, root},
|
|
"usage error": {"acme", Usage(fail), sub},
|
|
"reported": {"acme", Reported(fail), sub},
|
|
"no app above": {"acme", fail, t.TempDir()},
|
|
} {
|
|
if got := wrongDirectory(tc.name, tc.err, []string{"migrate"}, tc.dir); errors.As(got, &hint) && hint.Explanation == wrongDirectoryExplanation {
|
|
t.Errorf("%s: unexpected hint %#v", name, got)
|
|
}
|
|
}
|
|
}
|