okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
f6da61d
main
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 ) { 17testDaemon = os .Getenv ("ALBEDO_TEST_DAEMON" ) 18var snapshot string 19if testDaemon == "" { 20var err error 21snapshot ,err = os .MkdirTemp ("" ,"albedo-storage-tests-" ) 22if err != nil { 23fmt .Fprintln (os .Stderr ,err ) 24os .Exit (1 ) 25 } 26command := exec .Command ("../../../test/snapshot-daemon.sh" ,filepath .Join (snapshot ,"daemon" )) 27command .Stderr = os .Stderr 28output ,err := command .Output () 29if err != nil { 30os .RemoveAll (snapshot ) 31fmt .Fprintln (os .Stderr ,"build storage test daemon:" ,err ) 32os .Exit (1 ) 33 } 34testDaemon = strings .TrimSpace (string (output )) 35 } 36status := m .Run () 37if snapshot != "" { 38os .RemoveAll (snapshot ) 39 } 40os .Exit (status ) 41} 42 43func testCommand (ctx context.Context ,args ... string ) (* exec.Cmd ,error ) { 44return exec .CommandContext (ctx ,testDaemon ,args ... ),nil 45}