Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cmd/litestream/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,15 @@ Options:

-socket PATH
Path to control socket (default: /var/run/litestream.sock).

Examples:
# Register a database with an S3 replica.
$ litestream register -replica s3://mybucket/db /path/to/db

# Register a database with a file replica.
$ litestream register -replica file:///backup/path /path/to/db

# Register using a non-default control socket.
$ litestream register -socket /tmp/litestream.sock -replica s3://mybucket/db /path/to/db
`[1:])
}
48 changes: 48 additions & 0 deletions cmd/litestream/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package main_test

import (
"context"
"io"
"os"
"path/filepath"
"strings"
"testing"

"github.com/benbjohnson/litestream"
Expand Down Expand Up @@ -160,3 +163,48 @@ func TestRegisterCommand_Run(t *testing.T) {
}
})
}

func TestRegisterCommand_Usage(t *testing.T) {
output := captureStdout(t, func() {
(&main.RegisterCommand{}).Usage()
})

for _, example := range []string{
"Examples:",
"$ litestream register -replica s3://mybucket/db /path/to/db",
"$ litestream register -replica file:///backup/path /path/to/db",
"$ litestream register -socket /tmp/litestream.sock -replica s3://mybucket/db /path/to/db",
} {
if !strings.Contains(output, example) {
t.Fatalf("usage output missing %q:\n%s", example, output)
}
}
}

func captureStdout(t *testing.T, fn func()) string {
t.Helper()

orig := os.Stdout
r, w, err := os.Pipe()
if err != nil {
t.Fatal(err)
}
os.Stdout = w
t.Cleanup(func() {
os.Stdout = orig
})

fn()

if err := w.Close(); err != nil {
t.Fatal(err)
}
output, err := io.ReadAll(r)
if err != nil {
t.Fatal(err)
}
if err := r.Close(); err != nil {
t.Fatal(err)
}
return string(output)
}
Loading