2016-08-31 17:10:10 +00:00
|
|
|
package restic
|
|
|
|
|
2022-10-16 08:36:37 +00:00
|
|
|
import (
|
|
|
|
"testing"
|
2016-08-31 17:10:10 +00:00
|
|
|
|
2022-10-16 08:36:37 +00:00
|
|
|
rtest "github.com/restic/restic/internal/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHandleString(t *testing.T) {
|
|
|
|
rtest.Equals(t, "<data/foobar>", Handle{Type: PackFile, Name: "foobar"}.String())
|
|
|
|
rtest.Equals(t, "<lock/1>", Handle{Type: LockFile, Name: "1"}.String())
|
2016-08-31 17:10:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestHandleValid(t *testing.T) {
|
2022-10-16 08:36:37 +00:00
|
|
|
var handleTests = []struct {
|
|
|
|
h Handle
|
|
|
|
valid bool
|
|
|
|
}{
|
|
|
|
{Handle{Name: "foo"}, false},
|
|
|
|
{Handle{Type: 0}, false},
|
|
|
|
{Handle{Type: ConfigFile, Name: ""}, true},
|
|
|
|
{Handle{Type: PackFile, Name: ""}, false},
|
|
|
|
{Handle{Type: LockFile, Name: "010203040506"}, true},
|
|
|
|
}
|
|
|
|
|
2016-08-31 17:10:10 +00:00
|
|
|
for i, test := range handleTests {
|
|
|
|
err := test.h.Valid()
|
|
|
|
if err != nil && test.valid {
|
|
|
|
t.Errorf("test %v failed: error returned for valid handle: %v", i, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !test.valid && err == nil {
|
|
|
|
t.Errorf("test %v failed: expected error for invalid handle not found", i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|