@@ -41,6 +41,8 @@ type CLITest struct {
4141 fixedArgs []string
4242 Environment []string
4343
44+ DefaultRepositoryCreateFlags []string
45+
4446 PassthroughStderr bool
4547
4648 LogsDir string
@@ -70,7 +72,22 @@ func NewCLITest(t *testing.T) *CLITest {
7072 }
7173
7274 configDir := t .TempDir ()
73- logsDir := t .TempDir ()
75+
76+ cleanName := strings .ReplaceAll (strings .ReplaceAll (strings .ReplaceAll (
77+ t .Name (),
78+ "/" , "_" ), "\\ " , "_" ), ":" , "_" )
79+
80+ logsDir := filepath .Join (os .TempDir (), "kopia-logs" , cleanName + "." + clock .Now ().Local ().Format ("20060102150405" ))
81+
82+ t .Cleanup (func () {
83+ if t .Failed () {
84+ t .Logf ("logs are available in %v" , logsDir )
85+ return
86+ }
87+
88+ os .RemoveAll (logsDir )
89+ })
90+
7491 fixedArgs := []string {
7592 // use per-test config file, to avoid clobbering current user's setup.
7693 "--config-file" , filepath .Join (configDir , ".kopia.config" ),
@@ -87,13 +104,24 @@ func NewCLITest(t *testing.T) *CLITest {
87104 fixedArgs = append (fixedArgs , "--no-use-keyring" )
88105 }
89106
107+ var formatFlags []string
108+
109+ switch runtime .GOARCH {
110+ case "arm64" , "arm" :
111+ formatFlags = []string {
112+ "--encryption" , "CHACHA20-POLY1305-HMAC-SHA256" ,
113+ "--block-hash" , "BLAKE2S-256" ,
114+ }
115+ }
116+
90117 return & CLITest {
91- startTime : clock .Now (),
92- RepoDir : t .TempDir (),
93- ConfigDir : configDir ,
94- Exe : filepath .FromSlash (exe ),
95- fixedArgs : fixedArgs ,
96- LogsDir : logsDir ,
118+ startTime : clock .Now (),
119+ RepoDir : t .TempDir (),
120+ ConfigDir : configDir ,
121+ Exe : filepath .FromSlash (exe ),
122+ fixedArgs : fixedArgs ,
123+ DefaultRepositoryCreateFlags : formatFlags ,
124+ LogsDir : logsDir ,
97125 Environment : []string {
98126 "KOPIA_PASSWORD=" + TestRepoPassword ,
99127 "KOPIA_ADVANCED_COMMANDS=enabled" ,
@@ -117,11 +145,9 @@ func (e *CLITest) RunAndExpectSuccess(t *testing.T, args ...string) []string {
117145func (e * CLITest ) RunAndProcessStderr (t * testing.T , callback func (line string ) bool , args ... string ) * exec.Cmd {
118146 t .Helper ()
119147
120- t .Logf ("running 'kopia %v'" , strings .Join (args , " " ))
121- cmdArgs := append (append ([]string (nil ), e .fixedArgs ... ), args ... )
122-
123- c := exec .Command (e .Exe , cmdArgs ... )
148+ c := exec .Command (e .Exe , e .cmdArgs (args )... )
124149 c .Env = append (os .Environ (), e .Environment ... )
150+ t .Logf ("running '%v %v'" , c .Path , c .Args )
125151
126152 stderrPipe , err := c .StderrPipe ()
127153 if err != nil {
@@ -184,15 +210,27 @@ func (e *CLITest) RunAndVerifyOutputLineCount(t *testing.T, wantLines int, args
184210 return lines
185211}
186212
213+ func (e * CLITest ) cmdArgs (args []string ) []string {
214+ var suffix []string
215+
216+ // detect repository creation and override DefaultRepositoryCreateFlags for best
217+ // performance on the current platform.
218+ if len (args ) >= 2 && (args [0 ] == "repo" && args [1 ] == "create" ) {
219+ suffix = e .DefaultRepositoryCreateFlags
220+ }
221+
222+ return append (append (append ([]string (nil ), e .fixedArgs ... ), args ... ), suffix ... )
223+ }
224+
187225// Run executes kopia with given arguments and returns the output lines.
188226func (e * CLITest ) Run (t * testing.T , expectedError bool , args ... string ) (stdout , stderr []string , err error ) {
189227 t .Helper ()
190- t .Logf ("running '%v %v'" , e .Exe , strings .Join (args , " " ))
191- cmdArgs := append (append ([]string (nil ), e .fixedArgs ... ), args ... )
192228
193- c := exec .Command (e .Exe , cmdArgs ... )
229+ c := exec .Command (e .Exe , e . cmdArgs ( args ) ... )
194230 c .Env = append (os .Environ (), e .Environment ... )
195231
232+ t .Logf ("running '%v %v'" , c .Path , c .Args )
233+
196234 errOut := & bytes.Buffer {}
197235 c .Stderr = errOut
198236
0 commit comments