config: check a remote exists when creating a new one
This commit is contained in:
parent
3f7af64316
commit
049ff1f269
2 changed files with 29 additions and 10 deletions
|
@ -1084,12 +1084,17 @@ func fsOption() *fs.Option {
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRemoteName asks the user for a name for a remote
|
// NewRemoteName asks the user for a name for a new remote
|
||||||
func NewRemoteName() (name string) {
|
func NewRemoteName() (name string) {
|
||||||
for {
|
for {
|
||||||
fmt.Printf("name> ")
|
fmt.Printf("name> ")
|
||||||
name = ReadLine()
|
name = ReadLine()
|
||||||
err := fspath.CheckConfigName(name)
|
_, err := getConfigData().GetSection(name)
|
||||||
|
if err == nil {
|
||||||
|
fmt.Printf("Remote %q already exists.\n", name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
err = fspath.CheckConfigName(name)
|
||||||
switch {
|
switch {
|
||||||
case name == "":
|
case name == "":
|
||||||
fmt.Printf("Can't use empty name.\n")
|
fmt.Printf("Can't use empty name.\n")
|
||||||
|
|
|
@ -115,14 +115,6 @@ func TestCRUD(t *testing.T) {
|
||||||
assert.Equal(t, "true", FileGet("asdf", "bool"))
|
assert.Equal(t, "true", FileGet("asdf", "bool"))
|
||||||
assert.Equal(t, "secret", obscure.MustReveal(FileGet("asdf", "pass")))
|
assert.Equal(t, "secret", obscure.MustReveal(FileGet("asdf", "pass")))
|
||||||
|
|
||||||
// no-op rename, asdf → asdf
|
|
||||||
RenameRemote("asdf")
|
|
||||||
|
|
||||||
assert.Equal(t, []string{"asdf"}, configFile.GetSectionList())
|
|
||||||
assert.Equal(t, "config_test_remote", FileGet("asdf", "type"))
|
|
||||||
assert.Equal(t, "true", FileGet("asdf", "bool"))
|
|
||||||
assert.Equal(t, "secret", obscure.MustReveal(FileGet("asdf", "pass")))
|
|
||||||
|
|
||||||
// delete remote
|
// delete remote
|
||||||
DeleteRemote("asdf")
|
DeleteRemote("asdf")
|
||||||
assert.Equal(t, []string{}, configFile.GetSectionList())
|
assert.Equal(t, []string{}, configFile.GetSectionList())
|
||||||
|
@ -163,6 +155,28 @@ func TestChooseOption(t *testing.T) {
|
||||||
assert.Equal(t, "", FileGet("test", "pass"))
|
assert.Equal(t, "", FileGet("test", "pass"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNewRemoteName(t *testing.T) {
|
||||||
|
defer testConfigFile(t, "crud.conf")()
|
||||||
|
|
||||||
|
// script for creating remote
|
||||||
|
ReadLine = makeReadLine([]string{
|
||||||
|
"config_test_remote", // type
|
||||||
|
"true", // bool value
|
||||||
|
"n", // not required
|
||||||
|
"y", // looks good, save
|
||||||
|
})
|
||||||
|
NewRemote("test")
|
||||||
|
|
||||||
|
ReadLine = makeReadLine([]string{
|
||||||
|
"test", // already exists
|
||||||
|
"", // empty string not allowed
|
||||||
|
"bad@characters", // bad characters
|
||||||
|
"newname", // OK
|
||||||
|
})
|
||||||
|
|
||||||
|
assert.Equal(t, "newname", NewRemoteName())
|
||||||
|
}
|
||||||
|
|
||||||
func TestCreateUpatePasswordRemote(t *testing.T) {
|
func TestCreateUpatePasswordRemote(t *testing.T) {
|
||||||
defer testConfigFile(t, "update.conf")()
|
defer testConfigFile(t, "update.conf")()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue