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 Nireshwalia 46c3dc618a Add unrelease issue and cleanup configs
Removed extra environment variables
2023-01-30 16:46:52 -07:00

57 lines
1.3 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",
Domain: DefaultDomain,
Connections: DefaultConnections,
IdleTimeout: DefaultIdleTimeout,
}},
{"smb://shareaddress:456/sharename/directory", Config{
Address: "shareaddress",
Port: 456,
ShareName: "sharename",
Path: "directory",
Domain: DefaultDomain,
Connections: DefaultConnections,
IdleTimeout: DefaultIdleTimeout,
}},
}
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)
}
}
}