MCPcopy
hub / github.com/perkeep/perkeep / CmdWithEnv

Method CmdWithEnv

pkg/test/world.go:286–320  ·  view source on GitHub ↗
(binary string, env []string, args ...string)

Source from the content-addressed store, hash-verified

284}
285
286func (w *World) CmdWithEnv(binary string, env []string, args ...string) *exec.Cmd {
287 hasVerbose := func() bool {
288 for _, v := range args {
289 if v == "-verbose" || v == "--verbose" {
290 return true
291 }
292 }
293 return false
294 }
295 var cmd *exec.Cmd
296 switch binary {
297 case "pk-get", "pk-put", "pk", "pk-mount":
298 // TODO(mpl): lift the pk-put restriction when we have a unified logging mechanism
299 if binary == "pk-put" && !hasVerbose() {
300 // pk-put and pk are the only ones to have a -verbose flag through cmdmain
301 // but pk is never used. (and pk-mount does not even have a -verbose).
302 args = append([]string{"-verbose"}, args...)
303 }
304 binary := w.lookPathGobin(binary)
305
306 cmd = exec.Command(binary, args...)
307 clientConfigDir := filepath.Join(w.srcRoot, "config", "dev-client-dir")
308 cmd.Env = append(env,
309 "CAMLI_CONFIG_DIR="+clientConfigDir,
310 // Respected by env expansions in config/dev-client-dir/client-config.json:
311 "CAMLI_SERVER="+w.ServerBaseURL(),
312 "CAMLI_SECRET_RING="+w.SecretRingFile(),
313 "CAMLI_KEYID="+w.ClientIdentity(),
314 "CAMLI_AUTH=userpass:testuser:passTestWorld",
315 )
316 default:
317 panic("Unknown binary " + binary)
318 }
319 return cmd
320}
321
322func (w *World) ServerBaseURL() string {
323 return fmt.Sprintf("http://%s", w.addr)

Callers 4

CmdMethod · 0.95
TestCamputUploadOnceFunction · 0.80
TestAndroidCamputFileFunction · 0.80
pkmountTestFunction · 0.80

Implementers 2

testWorldpkg/gc/gc_test.go
Worldpkg/test/world.go

Calls 5

lookPathGobinMethod · 0.95
ServerBaseURLMethod · 0.95
SecretRingFileMethod · 0.95
ClientIdentityMethod · 0.95
CommandMethod · 0.65

Tested by 3

TestCamputUploadOnceFunction · 0.64
TestAndroidCamputFileFunction · 0.64
pkmountTestFunction · 0.64