backend: move backend implementation helpers to util package
This removes code that is only used within a backend implementation from the backend package. The latter now only contains code that also has external users.
This commit is contained in:
parent
8e6fdf5edf
commit
7881309d63
23 changed files with 158 additions and 135 deletions
41
internal/backend/util/foreground_test.go
Normal file
41
internal/backend/util/foreground_test.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package util_test
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/restic/restic/internal/backend/util"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
func TestForeground(t *testing.T) {
|
||||
err := os.Setenv("RESTIC_PASSWORD", "supersecret")
|
||||
rtest.OK(t, err)
|
||||
|
||||
cmd := exec.Command("env")
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
rtest.OK(t, err)
|
||||
|
||||
bg, err := util.StartForeground(cmd)
|
||||
rtest.OK(t, err)
|
||||
defer func() {
|
||||
rtest.OK(t, cmd.Wait())
|
||||
}()
|
||||
|
||||
err = bg()
|
||||
rtest.OK(t, err)
|
||||
|
||||
sc := bufio.NewScanner(stdout)
|
||||
for sc.Scan() {
|
||||
if strings.HasPrefix(sc.Text(), "RESTIC_PASSWORD=") {
|
||||
t.Error("subprocess got to see the password")
|
||||
}
|
||||
}
|
||||
rtest.OK(t, err)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue