1 Star 0 Fork 0

litian/machine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
sshcommander.go 1.34 KB
一键复制 编辑 原始数据 按行查看 历史
//Package provisiontest provides utilities for testing provisioners
package provisiontest
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
}
//FakeSSHCommander is an implementation of provision.SSHCommander to provide predictable responses set by testing code
//Extend it when needed
type FakeSSHCommander struct {
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
}
//SSHCommand is an implementation of provision.SSHCommander.SSHCommand to provide predictable responses set by testing code
func (sshCmder *FakeSSHCommander) SSHCommand(args string) (string, error) {
response, commandRegistered := sshCmder.Responses[args]
if !commandRegistered {
return "", errors.New("Command not registered in FakeSSHCommander")
}
return response, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/litian33/machine.git
git@gitee.com:litian33/machine.git
litian33
machine
machine
v0.9.0

搜索帮助

0d507c66 1850385 C8b1a773 1850385