CLI test coverage

This commit is contained in:
Ben Johnson
2022-01-11 13:05:14 -07:00
parent 3f0ec9fa9f
commit f308e0b154
154 changed files with 1619 additions and 312 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"reflect"
"testing"
"time"
"github.com/benbjohnson/litestream/internal"
)
@@ -59,3 +60,41 @@ func TestParseWALSegmentPath(t *testing.T) {
})
}
}
func TestTruncateDuration(t *testing.T) {
for _, tt := range []struct {
input, output time.Duration
}{
{0, 0 * time.Nanosecond},
{1, 1 * time.Nanosecond},
{12, 12 * time.Nanosecond},
{123, 123 * time.Nanosecond},
{1234, 1 * time.Microsecond},
{12345, 12 * time.Microsecond},
{123456, 123 * time.Microsecond},
{1234567, 1 * time.Millisecond},
{12345678, 12 * time.Millisecond},
{123456789, 123 * time.Millisecond},
{1234567890, 1200 * time.Millisecond},
{12345678900, 12 * time.Second},
{-1, -1 * time.Nanosecond},
{-12, -12 * time.Nanosecond},
{-123, -123 * time.Nanosecond},
{-1234, -1 * time.Microsecond},
{-12345, -12 * time.Microsecond},
{-123456, -123 * time.Microsecond},
{-1234567, -1 * time.Millisecond},
{-12345678, -12 * time.Millisecond},
{-123456789, -123 * time.Millisecond},
{-1234567890, -1200 * time.Millisecond},
{-12345678900, -12 * time.Second},
} {
t.Run(fmt.Sprint(int(tt.input)), func(t *testing.T) {
if got, want := internal.TruncateDuration(tt.input), tt.output; got != want {
t.Fatalf("duration=%s, want %s", got, want)
}
})
}
}