1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2025-03-16 00:00:05 +01:00
restic/internal/backend/smb/config_test.go
Aneesh N 375a9b7940
Add smb changes (#6)
* backend/smb: Add SMB backend and testcases

Add new SMB storage backend for restic.
Added test cases for testing SMB backend.

---------

Co-authored-by: Aneesh Nireshwalia <aneeshynot@gmail.com>
Co-authored-by: Srigovind Nayak <sgovind.dev@outlook.com>
2023-01-30 15:42:07 -07:00

51 lines
1.1 KiB
Go

package smb
import (
"strings"
"testing"
)
var configTests = []struct {
s string
cfg Config
}{
{"smb://shareaddress/sharename/directory", Config{
Address: "shareaddress",
Port: DefaultSmbPort,
ShareName: "sharename",
Path: "directory",
}},
{"smb://shareaddress:456/sharename/directory", Config{
Address: "shareaddress",
Port: 456,
ShareName: "sharename",
Path: "directory",
}},
}
func TestParseConfig(t *testing.T) {
for i, test := range configTests {
cfg, err := ParseConfig(test.s)
if err != nil {
t.Errorf("test %d:%s failed: %v", i, test.s, err)
continue
}
if cfg != test.cfg {
t.Errorf("test %d:\ninput:\n %s\n wrong config, want:\n %v\ngot:\n %v",
i, test.s, test.cfg, cfg)
continue
}
}
}
func TestParseError(t *testing.T) {
const prefix = "smb: invalid format,"
for _, s := range []string{"", "/", "//", "/sharename/directory"} {
_, err := ParseConfig("smb://" + s)
if err == nil || !strings.HasPrefix(err.Error(), prefix) {
t.Errorf("expected %q, got %q", prefix, err)
}
}
}