1
0
mirror of https://github.com/restic/restic.git synced 2024-07-07 09:30:53 +02:00
restic/internal/backend/smb/config_test.go
Aneesh Nireshwalia 5ff9f58fbb Add document and cleanup config
Add documentation for configuring smb repository.
Clean up configuration for smb. Renamed address to host.
Add option to configure user in smb repo url as well.
Options take highest precendence.
2023-01-30 19:45:37 -07:00

88 lines
2.1 KiB
Go

package smb
import (
"strings"
"testing"
)
var configTests = []struct {
s string
cfg Config
}{
{"smb://user@host/sharename/directory", Config{
Host: "host",
Port: DefaultSmbPort,
User: "user",
Domain: DefaultDomain,
ShareName: "sharename",
Path: "directory",
Connections: DefaultConnections,
IdleTimeout: DefaultIdleTimeout,
}},
{"smb://user@host:456/sharename/directory", Config{
Host: "host",
Port: 456,
User: "user",
Domain: DefaultDomain,
ShareName: "sharename",
Path: "directory",
Connections: DefaultConnections,
IdleTimeout: DefaultIdleTimeout,
}},
{"smb://host/sharename/directory", Config{
Host: "host",
Port: DefaultSmbPort,
Domain: DefaultDomain,
ShareName: "sharename",
Path: "directory",
Connections: DefaultConnections,
IdleTimeout: DefaultIdleTimeout,
}},
{"smb://host:446/sharename/directory", Config{
Host: "host",
Port: 446,
Domain: DefaultDomain,
ShareName: "sharename",
Path: "directory",
Connections: DefaultConnections,
IdleTimeout: DefaultIdleTimeout,
}},
{"smb:user@host:466/sharename/directory", Config{
Host: "host",
Port: 466,
User: "user",
Domain: DefaultDomain,
ShareName: "sharename",
Path: "directory",
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{"", "/", "//", "host", "user@host", "user@host:445", "/sharename/directory"} {
_, err := ParseConfig("smb://" + s)
if err == nil || !strings.HasPrefix(err.Error(), prefix) {
t.Errorf("expected %q, got %q", prefix, err)
}
}
}