mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
improve coverage in tests
This commit is contained in:
parent
d0ccf8e4e4
commit
bd2b9ac225
4 changed files with 68 additions and 1 deletions
30
ctl/backup_test.go
Normal file
30
ctl/backup_test.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// Copyright 2021 Molecula Corp. All rights reserved.
|
||||
package ctl
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBackupCommand_Run(t *testing.T) {
|
||||
cm := NewBackupCommand(os.Stdin, os.Stdout, os.Stderr)
|
||||
cm.OutputDir = ""
|
||||
err := cm.Run(context.Background())
|
||||
if !errors.Is(err, UsageError) {
|
||||
t.Fatalf("expected usage error, got %v", err)
|
||||
}
|
||||
cm.OutputDir = "foo"
|
||||
cm.Concurrency = 0
|
||||
err = cm.Run(context.Background())
|
||||
if !errors.Is(err, UsageError) {
|
||||
t.Fatalf("expected usage error, got %v", err)
|
||||
}
|
||||
cm.Concurrency = 1
|
||||
cm.HeaderTimeoutStr = "until the cat wakes up"
|
||||
err = cm.Run(context.Background())
|
||||
if !errors.Is(err, UsageError) {
|
||||
t.Fatalf("expected usage error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -80,7 +80,7 @@ func (cmd *RestoreTarCommand) Run(ctx context.Context) (err error) {
|
|||
} else {
|
||||
file, err := os.Open(cmd.Path)
|
||||
if err != nil {
|
||||
return (err)
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
f = file
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@ package ctl
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
|
@ -20,6 +22,17 @@ func TestRestoreTarCommand_Run(t *testing.T) {
|
|||
cm := NewRestoreTarCommand(stdin, stdout, stderr)
|
||||
hostport := cmd.API.Node().URI.HostPort()
|
||||
cm.Host = hostport
|
||||
cm.Path = ""
|
||||
err := cm.Run(context.Background())
|
||||
if !errors.Is(err, UsageError) {
|
||||
t.Fatalf("expected usage error with empty path, got %v", err)
|
||||
}
|
||||
cm.Path = "nonexistent-file"
|
||||
err = cm.Run(context.Background())
|
||||
if _, ok := err.(*os.PathError); !ok {
|
||||
t.Fatalf("expected path error with nonexistent path, got %v", err)
|
||||
}
|
||||
// use stdin
|
||||
cm.Path = "-"
|
||||
|
||||
resp, err := http.DefaultClient.Do(test.MustNewHTTPRequest("POST", "http://"+hostport+"/index/i", strings.NewReader("")))
|
||||
|
|
|
|||
24
ctl/restore_test.go
Normal file
24
ctl/restore_test.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright 2021 Molecula Corp. All rights reserved.
|
||||
package ctl
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRestoreCommand_Run(t *testing.T) {
|
||||
cm := NewRestoreCommand(os.Stdin, os.Stdout, os.Stderr)
|
||||
cm.Path = ""
|
||||
err := cm.Run(context.Background())
|
||||
if !errors.Is(err, UsageError) {
|
||||
t.Fatalf("expected usage error, got %v", err)
|
||||
}
|
||||
cm.Path = "foo"
|
||||
cm.Concurrency = 0
|
||||
err = cm.Run(context.Background())
|
||||
if !errors.Is(err, UsageError) {
|
||||
t.Fatalf("expected usage error, got %v", err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue