okami.mom/albedo

git clone https://git.nkp.pet/okami.mom/albedo

Aly Raffaufrefactor(cli): invoke daemon storage helpersf6da61d

main
1.0 KiB45 linesraw
1// Use the production helper for ownership tests, without booting its server.
2package storage
3
4import (
5	"context"
6	"fmt"
7	"os"
8	"os/exec"
9	"path/filepath"
10	"strings"
11	"testing"
12)
13
14var testDaemon string
15
16func TestMain(m *testing.M) {
17	testDaemon = os.Getenv("ALBEDO_TEST_DAEMON")
18	var snapshot string
19	if testDaemon == "" {
20		var err error
21		snapshot, err = os.MkdirTemp("", "albedo-storage-tests-")
22		if err != nil {
23			fmt.Fprintln(os.Stderr, err)
24			os.Exit(1)
25		}
26		command := exec.Command("../../../test/snapshot-daemon.sh", filepath.Join(snapshot, "daemon"))
27		command.Stderr = os.Stderr
28		output, err := command.Output()
29		if err != nil {
30			os.RemoveAll(snapshot)
31			fmt.Fprintln(os.Stderr, "build storage test daemon:", err)
32			os.Exit(1)
33		}
34		testDaemon = strings.TrimSpace(string(output))
35	}
36	status := m.Run()
37	if snapshot != "" {
38		os.RemoveAll(snapshot)
39	}
40	os.Exit(status)
41}
42
43func testCommand(ctx context.Context, args ...string) (*exec.Cmd, error) {
44	return exec.CommandContext(ctx, testDaemon, args...), nil
45}