38 lines
844 B
Go
38 lines
844 B
Go
package cli
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestInitWritesConfig(t *testing.T) {
|
|
dir := t.TempDir()
|
|
configPath := filepath.Join(dir, "config.toml")
|
|
dbPath := filepath.Join(dir, "gitcrawl.db")
|
|
app := New()
|
|
var stdout bytes.Buffer
|
|
app.Stdout = &stdout
|
|
|
|
err := app.Run(context.Background(), []string{"--config", configPath, "--json", "init", "--db", dbPath})
|
|
if err != nil {
|
|
t.Fatalf("run init: %v", err)
|
|
}
|
|
if !strings.Contains(stdout.String(), `"config_path"`) {
|
|
t.Fatalf("expected json init output, got %q", stdout.String())
|
|
}
|
|
}
|
|
|
|
func TestServeIsUnsupported(t *testing.T) {
|
|
app := New()
|
|
err := app.Run(context.Background(), []string{"serve"})
|
|
if err == nil {
|
|
t.Fatal("expected serve to fail")
|
|
}
|
|
if ExitCode(err) != 2 {
|
|
t.Fatalf("exit code: got %d want 2", ExitCode(err))
|
|
}
|
|
}
|