github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/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 SyslogUserGroup = syslogUserGroup 13 ) 14 15 type patcher interface { 16 PatchValue(interface{}, interface{}) 17 } 18 19 func PatchNewChan(patcher patcher) chan string { 20 ch := make(chan string, 1) 21 patcher.PatchValue(&newChan, func() chan string { return ch }) 22 return ch 23 } 24 25 func PatchNewConn(patcher patcher, stub *testing.Stub) *StubDbusAPI { 26 conn := &StubDbusAPI{Stub: stub} 27 patcher.PatchValue(&newConn, func() (dbusAPI, error) { return conn, nil }) 28 return conn 29 } 30 31 func PatchFileOps(patcher patcher, stub *testing.Stub) *StubFileOps { 32 fops := &StubFileOps{Stub: stub} 33 patcher.PatchValue(&removeAll, fops.RemoveAll) 34 patcher.PatchValue(&mkdirAll, fops.MkdirAll) 35 patcher.PatchValue(&createFile, fops.CreateFile) 36 return fops 37 } 38 39 func PatchExec(patcher patcher, stub *testing.Stub) *StubExec { 40 exec := &StubExec{Stub: stub} 41 patcher.PatchValue(&runCommands, exec.RunCommand) 42 return exec 43 }