MCPcopy
hub / github.com/benbjohnson/litestream / TestStartCommand_RunJSONOutput

Function TestStartCommand_RunJSONOutput

cmd/litestream/start_stop_test.go:16–62  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestStartCommand_RunJSONOutput(t *testing.T) {
17 db, sqldb := newStartStopCommandDB(t)
18 if err := sqldb.Close(); err != nil {
19 t.Fatal(err)
20 }
21 if err := db.Close(t.Context()); err != nil {
22 t.Fatal(err)
23 }
24
25 store := litestream.NewStore([]*litestream.DB{db}, litestream.CompactionLevels{{Level: 0}})
26 store.CompactionMonitorEnabled = false
27 defer store.Close(t.Context())
28
29 server := litestream.NewServer(store)
30 server.SocketPath = testSocketPath(t)
31 if err := server.Start(); err != nil {
32 t.Fatal(err)
33 }
34 defer server.Close()
35
36 output := captureStdout(t, func() {
37 cmd := &main.StartCommand{}
38 if err := cmd.Run(context.Background(), []string{"-json", "-socket", server.SocketPath, db.Path()}); err != nil {
39 t.Fatalf("unexpected error: %v", err)
40 }
41 })
42
43 var got main.StartStopResult
44 if err := json.Unmarshal([]byte(output), &got); err != nil {
45 t.Fatalf("failed to parse output: %v\n%s", err, output)
46 }
47 if got.DBPath != db.Path() {
48 t.Fatalf("unexpected db path: %s", got.DBPath)
49 }
50 if got.Status != "started" {
51 t.Fatalf("unexpected status: %s", got.Status)
52 }
53 if got.State != "running" {
54 t.Fatalf("unexpected state: %s", got.State)
55 }
56 if got.TXID == 0 {
57 t.Fatal("expected non-zero txid")
58 }
59 if got.Socket != server.SocketPath {
60 t.Fatalf("unexpected socket: %s", got.Socket)
61 }
62}
63
64func TestStartCommand_RunAlreadyRunning(t *testing.T) {
65 db, _ := newStartStopCommandDB(t)

Callers

nothing calls this directly

Calls 9

CloseMethod · 0.95
StartMethod · 0.95
CloseMethod · 0.95
RunMethod · 0.95
newStartStopCommandDBFunction · 0.85
captureStdoutFunction · 0.85
testSocketPathFunction · 0.70
CloseMethod · 0.45
PathMethod · 0.45

Tested by

no test coverage detected