mirror of
https://github.com/restic/restic.git
synced 2025-10-19 07:33:21 +00:00

Rough steps: ``` mv cmd/restic/global* cmd/restic/secondary_repo* internal/global/ sed -i "s/package main/package global/" internal/global/*.go Rename "GlobalOptions" to "Options" in internal/global/ Replace everywhere " GlobalOptions" -> " global.Options" Replace everywhere "\*GlobalOptions" -> " *global.Options" Make SecondaryRepoOptions public Make create public Make version public ```
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package global
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
rtest "github.com/restic/restic/internal/test"
|
|
)
|
|
|
|
func TestReadRepo(t *testing.T) {
|
|
tempDir := rtest.TempDir(t)
|
|
|
|
// test --repo option
|
|
var gopts Options
|
|
gopts.Repo = tempDir
|
|
repo, err := ReadRepo(gopts)
|
|
rtest.OK(t, err)
|
|
rtest.Equals(t, tempDir, repo)
|
|
|
|
// test --repository-file option
|
|
foo := filepath.Join(tempDir, "foo")
|
|
err = os.WriteFile(foo, []byte(tempDir+"\n"), 0666)
|
|
rtest.OK(t, err)
|
|
|
|
var gopts2 Options
|
|
gopts2.RepositoryFile = foo
|
|
repo, err = ReadRepo(gopts2)
|
|
rtest.OK(t, err)
|
|
rtest.Equals(t, tempDir, repo)
|
|
|
|
var gopts3 Options
|
|
gopts3.RepositoryFile = foo + "-invalid"
|
|
_, err = ReadRepo(gopts3)
|
|
if err == nil {
|
|
t.Fatal("must not read repository path from invalid file path")
|
|
}
|
|
}
|
|
|
|
func TestReadEmptyPassword(t *testing.T) {
|
|
opts := Options{InsecureNoPassword: true}
|
|
password, err := ReadPassword(context.TODO(), opts, "test")
|
|
rtest.OK(t, err)
|
|
rtest.Equals(t, "", password, "got unexpected password")
|
|
|
|
opts.Password = "invalid"
|
|
_, err = ReadPassword(context.TODO(), opts, "test")
|
|
rtest.Assert(t, strings.Contains(err.Error(), "must not be specified together with providing a password via a cli option or environment variable"), "unexpected error message, got %v", err)
|
|
}
|