github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/utils/syslog/testing_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package syslog 5 6 import ( 7 "github.com/juju/testing" 8 gc "gopkg.in/check.v1" 9 ) 10 11 // Stub stubs out the external functions used in the syslog package. 12 type Stub struct { 13 testing.Stub 14 15 Euid int 16 } 17 18 // Geteuid is a stub for os.Geteuid. 19 func (s *Stub) Geteuid() int { 20 s.AddCall("Geteuid") 21 22 // Pop off the err, even though we don't return it. 23 s.NextErr() 24 return s.Euid 25 } 26 27 // Restart is a stub for service.Restart. 28 func (s *Stub) Restart(name string) error { 29 s.AddCall("Restart", name) 30 31 return s.NextErr() 32 } 33 34 // BaseSuite is the base suite for use in tests in the syslog package. 35 type BaseSuite struct { 36 testing.IsolationSuite 37 38 Stub *Stub 39 } 40 41 func (s *BaseSuite) SetUpTest(c *gc.C) { 42 s.IsolationSuite.SetUpTest(c) 43 44 s.Stub = &Stub{} 45 s.PatchValue(&getEuid, s.Stub.Geteuid) 46 s.PatchValue(&restart, s.Stub.Restart) 47 }