github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/service/systemd/stubexec_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  	"github.com/juju/utils/exec"
     9  )
    10  
    11  type StubExec struct {
    12  	*testing.Stub
    13  
    14  	Responses []exec.ExecResponse
    15  }
    16  
    17  func (se *StubExec) SetResponses(resp ...exec.ExecResponse) {
    18  	se.Responses = resp
    19  }
    20  
    21  func (se *StubExec) RunCommand(args exec.RunParams) (*exec.ExecResponse, error) {
    22  	se.AddCall("RunCommand", args)
    23  
    24  	var response exec.ExecResponse
    25  	if len(se.Responses) > 0 {
    26  		response = se.Responses[0]
    27  		se.Responses = se.Responses[1:]
    28  	}
    29  	err := se.NextErr()
    30  	if err != nil {
    31  		return nil, err
    32  	}
    33  	return &response, nil
    34  }