chore(repo): reinitialize repository
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package cli_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"inbox/internal/cli"
|
||||
)
|
||||
|
||||
func TestRunSupportsServerAndAPI(t *testing.T) {
|
||||
var stderr bytes.Buffer
|
||||
handlers := cli.Handlers{
|
||||
PrintUsage: func(w io.Writer) {
|
||||
_, _ = io.WriteString(w, "Usage: inbox <command> [flags]\n")
|
||||
},
|
||||
RunServer: func([]string) error {
|
||||
return assertErr("--workspaces-dir is required")
|
||||
},
|
||||
RunAPI: func([]string) error {
|
||||
return assertErr("api failed")
|
||||
},
|
||||
}
|
||||
|
||||
if code := cli.Run([]string{"inbox"}, &stderr, handlers); code != 1 {
|
||||
t.Fatalf("cli.Run missing command exit code = %d, want 1", code)
|
||||
}
|
||||
if !strings.Contains(stderr.String(), "Usage: inbox <command> [flags]") {
|
||||
t.Fatalf("missing command stderr = %q", stderr.String())
|
||||
}
|
||||
|
||||
stderr.Reset()
|
||||
if code := cli.Run([]string{"inbox", "web"}, &stderr, handlers); code != 1 {
|
||||
t.Fatalf("cli.Run legacy command exit code = %d, want 1", code)
|
||||
}
|
||||
if !strings.Contains(stderr.String(), "Usage: inbox <command> [flags]") {
|
||||
t.Fatalf("legacy command stderr = %q", stderr.String())
|
||||
}
|
||||
|
||||
stderr.Reset()
|
||||
if code := cli.Run([]string{"inbox", "server"}, &stderr, handlers); code != 1 {
|
||||
t.Fatalf("cli.Run server error exit code = %d, want 1", code)
|
||||
}
|
||||
if !strings.Contains(stderr.String(), "error: --workspaces-dir is required") {
|
||||
t.Fatalf("server error stderr = %q", stderr.String())
|
||||
}
|
||||
|
||||
stderr.Reset()
|
||||
if code := cli.Run([]string{"inbox", "api"}, &stderr, handlers); code != 1 {
|
||||
t.Fatalf("cli.Run api error exit code = %d, want 1", code)
|
||||
}
|
||||
if !strings.Contains(stderr.String(), "error: api failed") {
|
||||
t.Fatalf("api error stderr = %q", stderr.String())
|
||||
}
|
||||
}
|
||||
|
||||
type assertErr string
|
||||
|
||||
func (e assertErr) Error() string {
|
||||
return string(e)
|
||||
}
|
||||
Reference in New Issue
Block a user