github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/service/systemd/export_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package systemd 5 6 import ( 7 "github.com/juju/testing" 8 ) 9 10 var ( 11 Serialize = serialize 12 ) 13 14 type patcher interface { 15 PatchValue(interface{}, interface{}) 16 } 17 18 func PatchNewChan(patcher patcher) chan string { 19 ch := make(chan string, 1) 20 patcher.PatchValue(&newChan, func() chan string { return ch }) 21 return ch 22 } 23 24 func PatchNewConn(patcher patcher, stub *testing.Stub) *StubDbusAPI { 25 conn := &StubDbusAPI{Stub: stub} 26 patcher.PatchValue(&newConn, func() (dbusAPI, error) { return conn, nil }) 27 return conn 28 } 29 30 func PatchFileOps(patcher patcher, stub *testing.Stub) *StubFileOps { 31 fops := &StubFileOps{Stub: stub} 32 patcher.PatchValue(&removeAll, fops.RemoveAll) 33 patcher.PatchValue(&mkdirAll, fops.MkdirAll) 34 patcher.PatchValue(&createFile, fops.CreateFile) 35 return fops 36 } 37 38 func PatchExec(patcher patcher, stub *testing.Stub) *StubExec { 39 exec := &StubExec{Stub: stub} 40 patcher.PatchValue(&runCommands, exec.RunCommand) 41 return exec 42 }