mirror of
https://github.com/cupcakearmy/autorestic.git
synced 2025-09-06 10:30:39 +00:00
Compare commits
3 Commits
dependabot
...
0a94869fc6
Author | SHA1 | Date | |
---|---|---|---|
|
0a94869fc6 | ||
|
51a8298f2a | ||
|
f6aa45fd6c |
@@ -1,4 +1,4 @@
|
|||||||
FROM golang:1.24-alpine as builder
|
FROM golang:1.23-alpine as builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY go.* .
|
COPY go.* .
|
||||||
@@ -6,7 +6,7 @@ RUN go mod download
|
|||||||
COPY . .
|
COPY . .
|
||||||
RUN go build
|
RUN go build
|
||||||
|
|
||||||
FROM restic/restic:0.18.0
|
FROM restic/restic:0.17.1
|
||||||
RUN apk add --no-cache rclone bash curl docker-cli
|
RUN apk add --no-cache rclone bash curl docker-cli
|
||||||
COPY --from=builder /app/autorestic /usr/bin/autorestic
|
COPY --from=builder /app/autorestic /usr/bin/autorestic
|
||||||
ENTRYPOINT []
|
ENTRYPOINT []
|
||||||
|
@@ -18,11 +18,9 @@ var backupCmd = &cobra.Command{
|
|||||||
err := lock.Lock()
|
err := lock.Lock()
|
||||||
CheckErr(err)
|
CheckErr(err)
|
||||||
defer lock.Unlock()
|
defer lock.Unlock()
|
||||||
dry, _ := cmd.Flags().GetBool("dry-run")
|
|
||||||
|
|
||||||
selected, err := internal.GetAllOrSelected(cmd, false)
|
selected, err := internal.GetAllOrSelected(cmd, false)
|
||||||
CheckErr(err)
|
CheckErr(err)
|
||||||
|
|
||||||
errors := 0
|
errors := 0
|
||||||
for _, name := range selected {
|
for _, name := range selected {
|
||||||
var splitted = strings.Split(name, "@")
|
var splitted = strings.Split(name, "@")
|
||||||
@@ -31,7 +29,7 @@ var backupCmd = &cobra.Command{
|
|||||||
specificBackend = splitted[1]
|
specificBackend = splitted[1]
|
||||||
}
|
}
|
||||||
location, _ := internal.GetLocation(splitted[0])
|
location, _ := internal.GetLocation(splitted[0])
|
||||||
errs := location.Backup(false, dry, specificBackend)
|
errs := location.Backup(false, specificBackend)
|
||||||
for _, err := range errs {
|
for _, err := range errs {
|
||||||
colors.Error.Printf("%s\n\n", err)
|
colors.Error.Printf("%s\n\n", err)
|
||||||
errors++
|
errors++
|
||||||
@@ -46,5 +44,4 @@ var backupCmd = &cobra.Command{
|
|||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(backupCmd)
|
rootCmd.AddCommand(backupCmd)
|
||||||
internal.AddFlagsToCommand(backupCmd, false)
|
internal.AddFlagsToCommand(backupCmd, false)
|
||||||
backupCmd.Flags().Bool("dry-run", false, "do not write changes, show what would be affected")
|
|
||||||
}
|
}
|
||||||
|
@@ -42,6 +42,7 @@ func init() {
|
|||||||
rootCmd.PersistentFlags().BoolVarP(&flags.VERBOSE, "verbose", "v", false, "verbose mode")
|
rootCmd.PersistentFlags().BoolVarP(&flags.VERBOSE, "verbose", "v", false, "verbose mode")
|
||||||
rootCmd.PersistentFlags().StringVar(&flags.RESTIC_BIN, "restic-bin", "restic", "specify custom restic binary")
|
rootCmd.PersistentFlags().StringVar(&flags.RESTIC_BIN, "restic-bin", "restic", "specify custom restic binary")
|
||||||
rootCmd.PersistentFlags().StringVar(&flags.DOCKER_IMAGE, "docker-image", "cupcakearmy/autorestic:"+internal.VERSION, "specify a custom docker image")
|
rootCmd.PersistentFlags().StringVar(&flags.DOCKER_IMAGE, "docker-image", "cupcakearmy/autorestic:"+internal.VERSION, "specify a custom docker image")
|
||||||
|
rootCmd.PersistentFlags().StringVar(&flags.LOCKFILE_PATH, "lockfile-path", "", "specify a custom path for the lockfile (defaults to .autorestic.lock.yml next to the loaded autorestic config file)")
|
||||||
cobra.OnInitialize(initConfig)
|
cobra.OnInitialize(initConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,14 +1,11 @@
|
|||||||
# Backup
|
# Backup
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
autorestic backup [-l, --location] [-a, --all] [--dry-run]
|
autorestic backup [-l, --location] [-a, --all]
|
||||||
```
|
```
|
||||||
|
|
||||||
Performs a backup of all locations if the `-a` flag is passed. To only backup some locations pass one or more `-l` or `--location` flags.
|
Performs a backup of all locations if the `-a` flag is passed. To only backup some locations pass one or more `-l` or `--location` flags.
|
||||||
|
|
||||||
The `--dry-run` flag will do a dry run showing what would have been deleted, but won't touch the actual data.
|
|
||||||
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# All
|
# All
|
||||||
autorestic backup -a
|
autorestic backup -a
|
||||||
|
@@ -34,3 +34,11 @@ With `--restic-bin` you can specify to run a specific restic binary. This can be
|
|||||||
```bash
|
```bash
|
||||||
autorestic --restic-bin /some/path/to/my/custom/restic/binary
|
autorestic --restic-bin /some/path/to/my/custom/restic/binary
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## `--lockfile-path`
|
||||||
|
|
||||||
|
Specify the path for the lockfile used by `autorestic`. If omitted, this will default to `.autorestic.lock.yml` next to the loaded config file.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
autorestic --lockfile-path /path/to/my/.autorestic.lock.yml
|
||||||
|
```
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e -o pipefail
|
|
||||||
shopt -s nocaseglob
|
shopt -s nocaseglob
|
||||||
|
|
||||||
OUT_FILE=/usr/local/bin/autorestic
|
OUT_FILE=/usr/local/bin/autorestic
|
||||||
|
@@ -14,19 +14,19 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type BackendRest struct {
|
type BackendRest struct {
|
||||||
User string `mapstructure:"user,omitempty" yaml:"user,omitempty"`
|
User string `mapstructure:"user,omitempty"`
|
||||||
Password string `mapstructure:"password,omitempty" yaml:"password,omitempty"`
|
Password string `mapstructure:"password,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Backend struct {
|
type Backend struct {
|
||||||
name string
|
name string
|
||||||
Type string `mapstructure:"type,omitempty" yaml:"type,omitempty"`
|
Type string `mapstructure:"type,omitempty"`
|
||||||
Path string `mapstructure:"path,omitempty" yaml:"path,omitempty"`
|
Path string `mapstructure:"path,omitempty"`
|
||||||
Key string `mapstructure:"key,omitempty" yaml:"key,omitempty"`
|
Key string `mapstructure:"key,omitempty"`
|
||||||
RequireKey bool `mapstructure:"requireKey,omitempty" yaml:"requireKey,omitempty"`
|
RequireKey bool `mapstructure:"requireKey,omitempty"`
|
||||||
Env map[string]string `mapstructure:"env,omitempty" yaml:"env,omitempty"`
|
Env map[string]string `mapstructure:"env,omitempty"`
|
||||||
Rest BackendRest `mapstructure:"rest,omitempty" yaml:"rest,omitempty"`
|
Rest BackendRest `mapstructure:"rest,omitempty"`
|
||||||
Options Options `mapstructure:"options,omitempty" yaml:"options,omitempty"`
|
Options Options `mapstructure:"options,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBackend(name string) (Backend, bool) {
|
func GetBackend(name string) (Backend, bool) {
|
||||||
|
@@ -23,11 +23,11 @@ type OptionMap map[string][]interface{}
|
|||||||
type Options map[string]OptionMap
|
type Options map[string]OptionMap
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Version string `mapstructure:"version" yaml:"version"`
|
Version string `mapstructure:"version"`
|
||||||
Extras interface{} `mapstructure:"extras" yaml:"extras"`
|
Extras interface{} `mapstructure:"extras"`
|
||||||
Locations map[string]Location `mapstructure:"locations" yaml:"locations"`
|
Locations map[string]Location `mapstructure:"locations"`
|
||||||
Backends map[string]Backend `mapstructure:"backends" yaml:"backends"`
|
Backends map[string]Backend `mapstructure:"backends"`
|
||||||
Global Options `mapstructure:"global" yaml:"global"`
|
Global Options `mapstructure:"global"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var once sync.Once
|
var once sync.Once
|
||||||
@@ -188,34 +188,18 @@ func CheckConfig() error {
|
|||||||
if !CheckIfResticIsCallable() {
|
if !CheckIfResticIsCallable() {
|
||||||
return fmt.Errorf(`%s was not found. Install either with "autorestic install" or manually`, flags.RESTIC_BIN)
|
return fmt.Errorf(`%s was not found. Install either with "autorestic install" or manually`, flags.RESTIC_BIN)
|
||||||
}
|
}
|
||||||
|
|
||||||
cwd, _ := GetPathRelativeToConfig(".")
|
|
||||||
for name, location := range c.Locations {
|
|
||||||
location.name = name
|
|
||||||
|
|
||||||
// Hooks before location validation
|
|
||||||
options := ExecuteOptions{
|
|
||||||
Command: "bash",
|
|
||||||
Dir: cwd,
|
|
||||||
Envs: map[string]string{
|
|
||||||
"AUTORESTIC_LOCATION": location.name,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if err := location.ExecuteHooks(location.Hooks.PreValidate, options); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := location.validate(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for name, backend := range c.Backends {
|
for name, backend := range c.Backends {
|
||||||
backend.name = name
|
backend.name = name
|
||||||
if err := backend.validate(); err != nil {
|
if err := backend.validate(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for name, location := range c.Locations {
|
||||||
|
location.name = name
|
||||||
|
if err := location.validate(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,15 +1,10 @@
|
|||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestOptionToString(t *testing.T) {
|
func TestOptionToString(t *testing.T) {
|
||||||
@@ -148,48 +143,6 @@ func TestGetOptionsMultipleKeys(t *testing.T) {
|
|||||||
reflect.DeepEqual(result, expected)
|
reflect.DeepEqual(result, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSaveConfigProducesReadableConfig(t *testing.T) {
|
|
||||||
workDir := t.TempDir()
|
|
||||||
viper.SetConfigFile(path.Join(workDir, ".autorestic.yml"))
|
|
||||||
|
|
||||||
// Required to appease the config reader
|
|
||||||
viper.Set("version", 2)
|
|
||||||
|
|
||||||
c := Config{
|
|
||||||
Version: "2",
|
|
||||||
Locations: map[string]Location{
|
|
||||||
"test": {
|
|
||||||
Type: "local",
|
|
||||||
name: "test",
|
|
||||||
From: []string{"in-dir"},
|
|
||||||
To: []string{"test"},
|
|
||||||
// ForgetOption & ConfigOption have previously marshalled in a way that
|
|
||||||
// can't get read correctly
|
|
||||||
ForgetOption: "foo",
|
|
||||||
CopyOption: map[string][]string{"foo": {"bar"}},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Backends: map[string]Backend{
|
|
||||||
"test": {
|
|
||||||
name: "test",
|
|
||||||
Type: "local",
|
|
||||||
Path: "backup-target",
|
|
||||||
Key: "supersecret",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
err := c.SaveConfig()
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
// Ensure we the config reading logic actually runs
|
|
||||||
config = nil
|
|
||||||
once = sync.Once{}
|
|
||||||
readConfig := GetConfig()
|
|
||||||
assert.NotNil(t, readConfig)
|
|
||||||
assert.Equal(t, c, *readConfig)
|
|
||||||
}
|
|
||||||
|
|
||||||
func assertEqual[T comparable](t testing.TB, result, expected T) {
|
func assertEqual[T comparable](t testing.TB, result, expected T) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
|
@@ -1,22 +1,12 @@
|
|||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func RunCron() error {
|
func RunCron() error {
|
||||||
c := GetConfig()
|
c := GetConfig()
|
||||||
var errs []error
|
|
||||||
for name, l := range c.Locations {
|
for name, l := range c.Locations {
|
||||||
l.name = name
|
l.name = name
|
||||||
if err := l.RunCron(); err != nil {
|
if err := l.RunCron(); err != nil {
|
||||||
errs = append(errs, err)
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(errs) > 0 {
|
|
||||||
return fmt.Errorf("Encountered errors during cron process:\n%w", errors.Join(errs...))
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,10 @@
|
|||||||
package flags
|
package flags
|
||||||
|
|
||||||
var (
|
var (
|
||||||
CI bool = false
|
CI bool = false
|
||||||
VERBOSE bool = false
|
VERBOSE bool = false
|
||||||
CRON_LEAN bool = false
|
CRON_LEAN bool = false
|
||||||
RESTIC_BIN string
|
RESTIC_BIN string
|
||||||
DOCKER_IMAGE string
|
DOCKER_IMAGE string
|
||||||
|
LOCKFILE_PATH string
|
||||||
)
|
)
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
@@ -34,26 +33,26 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Hooks struct {
|
type Hooks struct {
|
||||||
Dir string `mapstructure:"dir" yaml:"dir"`
|
Dir string `mapstructure:"dir"`
|
||||||
PreValidate HookArray `mapstructure:"prevalidate,omitempty" yaml:"prevalidate,omitempty"`
|
PreValidate HookArray `mapstructure:"prevalidate,omitempty"`
|
||||||
Before HookArray `mapstructure:"before,omitempty" yaml:"before,omitempty"`
|
Before HookArray `mapstructure:"before,omitempty"`
|
||||||
After HookArray `mapstructure:"after,omitempty" yaml:"after,omitempty"`
|
After HookArray `mapstructure:"after,omitempty"`
|
||||||
Success HookArray `mapstructure:"success,omitempty" yaml:"success,omitempty"`
|
Success HookArray `mapstructure:"success,omitempty"`
|
||||||
Failure HookArray `mapstructure:"failure,omitempty" yaml:"failure,omitempty"`
|
Failure HookArray `mapstructure:"failure,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LocationCopy = map[string][]string
|
type LocationCopy = map[string][]string
|
||||||
|
|
||||||
type Location struct {
|
type Location struct {
|
||||||
name string `mapstructure:",omitempty" yaml:",omitempty"`
|
name string `mapstructure:",omitempty"`
|
||||||
From []string `mapstructure:"from,omitempty" yaml:"from,omitempty"`
|
From []string `mapstructure:"from,omitempty"`
|
||||||
Type string `mapstructure:"type,omitempty" yaml:"type,omitempty"`
|
Type string `mapstructure:"type,omitempty"`
|
||||||
To []string `mapstructure:"to,omitempty" yaml:"to,omitempty"`
|
To []string `mapstructure:"to,omitempty"`
|
||||||
Hooks Hooks `mapstructure:"hooks,omitempty" yaml:"hooks,omitempty"`
|
Hooks Hooks `mapstructure:"hooks,omitempty"`
|
||||||
Cron string `mapstructure:"cron,omitempty" yaml:"cron,omitempty"`
|
Cron string `mapstructure:"cron,omitempty"`
|
||||||
Options Options `mapstructure:"options,omitempty" yaml:"options,omitempty"`
|
Options Options `mapstructure:"options,omitempty"`
|
||||||
ForgetOption LocationForgetOption `mapstructure:"forget,omitempty" yaml:"forget,omitempty"`
|
ForgetOption LocationForgetOption `mapstructure:"forget,omitempty"`
|
||||||
CopyOption LocationCopy `mapstructure:"copy,omitempty" yaml:"copy,omitempty"`
|
CopyOption LocationCopy `mapstructure:"copy,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetLocation(name string) (Location, bool) {
|
func GetLocation(name string) (Location, bool) {
|
||||||
@@ -168,7 +167,7 @@ func (l Location) getLocationTags() string {
|
|||||||
return buildTag("location", l.name)
|
return buildTag("location", l.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l Location) Backup(cron bool, dry bool, specificBackend string) []error {
|
func (l Location) Backup(cron bool, specificBackend string) []error {
|
||||||
var errors []error
|
var errors []error
|
||||||
var backends []string
|
var backends []string
|
||||||
colors.PrimaryPrint(" Backing up location \"%s\" ", l.name)
|
colors.PrimaryPrint(" Backing up location \"%s\" ", l.name)
|
||||||
@@ -228,9 +227,6 @@ func (l Location) Backup(cron bool, dry bool, specificBackend string) []error {
|
|||||||
if cron {
|
if cron {
|
||||||
cmd = append(cmd, "--tag", buildTag("cron"))
|
cmd = append(cmd, "--tag", buildTag("cron"))
|
||||||
}
|
}
|
||||||
if dry {
|
|
||||||
cmd = append(cmd, "--dry-run")
|
|
||||||
}
|
|
||||||
cmd = append(cmd, "--tag", l.getLocationTags())
|
cmd = append(cmd, "--tag", l.getLocationTags())
|
||||||
backupOptions := ExecuteOptions{
|
backupOptions := ExecuteOptions{
|
||||||
Envs: env,
|
Envs: env,
|
||||||
@@ -450,10 +446,7 @@ func (l Location) RunCron() error {
|
|||||||
now := time.Now()
|
now := time.Now()
|
||||||
if now.After(next) {
|
if now.After(next) {
|
||||||
lock.SetCron(l.name, now.Unix())
|
lock.SetCron(l.name, now.Unix())
|
||||||
errs := l.Backup(true, false, "")
|
l.Backup(true, "")
|
||||||
if len(errs) > 0 {
|
|
||||||
return fmt.Errorf("Failed to backup location \"%s\":\n%w", l.name, errors.Join(errs...))
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if !flags.CRON_LEAN {
|
if !flags.CRON_LEAN {
|
||||||
colors.Body.Printf("Skipping \"%s\", not due yet.\n", l.name)
|
colors.Body.Printf("Skipping \"%s\", not due yet.\n", l.name)
|
||||||
|
@@ -18,18 +18,28 @@ const (
|
|||||||
RUNNING = "running"
|
RUNNING = "running"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// getLockfilePath returns the path to the lockfile. If flags.LOCKFILE_PATH is
|
||||||
|
// set, its value is used, otherwise the path is generated relative to the
|
||||||
|
// config file.
|
||||||
|
func getLockfilePath() string {
|
||||||
|
if flags.LOCKFILE_PATH != "" {
|
||||||
|
return flags.LOCKFILE_PATH
|
||||||
|
} else {
|
||||||
|
p := viper.ConfigFileUsed()
|
||||||
|
if p == "" {
|
||||||
|
colors.Error.Println("cannot lock before reading config location")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
return path.Join(path.Dir(p), ".autorestic.lock.yml")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getLock() *viper.Viper {
|
func getLock() *viper.Viper {
|
||||||
if lock == nil {
|
if lock == nil {
|
||||||
|
|
||||||
once.Do(func() {
|
once.Do(func() {
|
||||||
lock = viper.New()
|
lock = viper.New()
|
||||||
lock.SetDefault("running", false)
|
lock.SetDefault("running", false)
|
||||||
p := viper.ConfigFileUsed()
|
file = getLockfilePath()
|
||||||
if p == "" {
|
|
||||||
colors.Error.Println("cannot lock before reading config location")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
file = path.Join(path.Dir(p), ".autorestic.lock.yml")
|
|
||||||
if !flags.CRON_LEAN {
|
if !flags.CRON_LEAN {
|
||||||
colors.Faint.Println("Using lock:\t", file)
|
colors.Faint.Println("Using lock:\t", file)
|
||||||
}
|
}
|
||||||
|
@@ -7,6 +7,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/cupcakearmy/autorestic/internal/flags"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -28,6 +29,37 @@ func setup(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetLockfilePath(t *testing.T) {
|
||||||
|
t.Run("when flags.LOCKFILE_PATH is set", func(t *testing.T) {
|
||||||
|
flags.LOCKFILE_PATH = "/path/to/my/autorestic.lock.yml"
|
||||||
|
defer func() { flags.LOCKFILE_PATH = "" }()
|
||||||
|
|
||||||
|
p := getLockfilePath()
|
||||||
|
|
||||||
|
if p != "/path/to/my/autorestic.lock.yml" {
|
||||||
|
t.Errorf("got %v, want %v", p, "/path/to/my/autorestic.lock.yml")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("when flags.LOCKFILE_PATH is set", func(t *testing.T) {
|
||||||
|
d, err := os.MkdirTemp("", testDirectory)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("error creating temp dir: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
viper.SetConfigFile(d + "/.autorestic.yml")
|
||||||
|
defer viper.Reset()
|
||||||
|
|
||||||
|
flags.LOCKFILE_PATH = ""
|
||||||
|
|
||||||
|
p := getLockfilePath()
|
||||||
|
|
||||||
|
if p != d+"/.autorestic.lock.yml" {
|
||||||
|
t.Errorf("got %v, want %v", p, d+"/.autorestic.lock.yml")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestLock(t *testing.T) {
|
func TestLock(t *testing.T) {
|
||||||
setup(t)
|
setup(t)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user