2016-01-08 21:17:54 +01:00
//Package provisiontest provides utilities for testing provisioners
package provisiontest
2016-01-15 21:13:29 +01:00
import "errors"
//FakeSSHCommanderOptions is intended to create a FakeSSHCommander without actually knowing the underlying sshcommands by passing it to NewSSHCommander
type FakeSSHCommanderOptions struct {
//Result of the ssh command to look up the FilesystemType
FilesystemType string
}
2016-01-08 21:17:54 +01:00
//FakeSSHCommander is an implementation of provision.SSHCommander to provide predictable responses set by testing code
//Extend it when needed
type FakeSSHCommander struct {
2016-01-15 21:13:29 +01:00
Responses map [ string ] string
}
//NewFakeSSHCommander creates a FakeSSHCommander without actually knowing the underlying sshcommands
func NewFakeSSHCommander ( options FakeSSHCommanderOptions ) * FakeSSHCommander {
if options . FilesystemType == "" {
options . FilesystemType = "ext4"
}
sshCmder := & FakeSSHCommander {
Responses : map [ string ] string {
"stat -f -c %T /var/lib" : options . FilesystemType + "\n" ,
} ,
}
return sshCmder
2016-01-08 21:17:54 +01:00
}
//SSHCommand is an implementation of provision.SSHCommander.SSHCommand to provide predictable responses set by testing code
2016-01-15 21:13:29 +01:00
func ( sshCmder * FakeSSHCommander ) SSHCommand ( args string ) ( string , error ) {
response , commandRegistered := sshCmder . Responses [ args ]
if ! commandRegistered {
return "" , errors . New ( "Command not registered in FakeSSHCommander" )
2016-01-08 21:17:54 +01:00
}
2016-01-15 21:13:29 +01:00
return response , nil
2016-01-08 21:17:54 +01:00
}