Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4734 from maouw/enhancement/envvar-for-host
Add support for specifying --host via environment variable
- Loading branch information
Showing
4 changed files
with
90 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Enhancement: Allow specifying `--host` via environment variable | ||
|
||
Restic commands that operate on snapshots, such as `restic backup` and | ||
`restic snapshots`, support the `--host` flag to specify the hostname for | ||
grouoping snapshots. They now permit selecting the hostname via the | ||
environment variable `RESTIC_HOST`. `--host` still takes precedence over the | ||
environment variable. | ||
|
||
https://github.com/restic/restic/issues/4733 | ||
https://github.com/restic/restic/pull/4734 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/restic/restic/internal/restic" | ||
rtest "github.com/restic/restic/internal/test" | ||
"github.com/spf13/pflag" | ||
) | ||
|
||
func TestSnapshotFilter(t *testing.T) { | ||
for _, test := range []struct { | ||
name string | ||
args []string | ||
expected []string | ||
env string | ||
}{ | ||
{ | ||
"no value", | ||
[]string{}, | ||
nil, | ||
"", | ||
}, | ||
{ | ||
"args only", | ||
[]string{"--host", "abc"}, | ||
[]string{"abc"}, | ||
"", | ||
}, | ||
{ | ||
"env default", | ||
[]string{}, | ||
[]string{"def"}, | ||
"def", | ||
}, | ||
{ | ||
"both", | ||
[]string{"--host", "abc"}, | ||
[]string{"abc"}, | ||
"def", | ||
}, | ||
} { | ||
t.Run(test.name, func(t *testing.T) { | ||
t.Setenv("RESTIC_HOST", test.env) | ||
|
||
for _, mode := range []bool{false, true} { | ||
set := pflag.NewFlagSet("test", pflag.PanicOnError) | ||
flt := &restic.SnapshotFilter{} | ||
if mode { | ||
initMultiSnapshotFilter(set, flt, false) | ||
} else { | ||
initSingleSnapshotFilter(set, flt) | ||
} | ||
err := set.Parse(test.args) | ||
rtest.OK(t, err) | ||
|
||
rtest.Equals(t, test.expected, flt.Hosts, "unexpected hosts") | ||
} | ||
}) | ||
} | ||
} |