当前位置: 首页>>代码示例>>Golang>>正文


Golang fakes.FakeCmdRunner类代码示例

本文整理汇总了Golang中github.com/cloudfoundry/bosh-utils/system/fakes.FakeCmdRunner的典型用法代码示例。如果您正苦于以下问题:Golang FakeCmdRunner类的具体用法?Golang FakeCmdRunner怎么用?Golang FakeCmdRunner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FakeCmdRunner类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1:

		It("allows lazy itable support", func() {
			fakeRunner := fakesys.NewFakeCmdRunner()
			fakeFs := fakesys.NewFakeFileSystem()
			fakeFs.WriteFile("/sys/fs/ext4/features/lazy_itable_init", []byte{})
			fakeRunner.AddCmdResult("blkid -p /dev/xvda2", fakesys.FakeCmdResult{Stdout: `xxxxx TYPE="ext2" yyyy zzzz`})

			formatter := NewLinuxFormatter(fakeRunner, fakeFs)
			formatter.Format("/dev/xvda2", FileSystemExt4)

			Expect(2).To(Equal(len(fakeRunner.RunCommands)))
			Expect(fakeRunner.RunCommands[1]).To(Equal([]string{"mke2fs", "-t", "ext4", "-j", "-E", "lazy_itable_init=1", "/dev/xvda2"}))

		})

		Context("when mke2fs errors", func() {
			var fakeRunner *fakesys.FakeCmdRunner
			var fakeFs *fakesys.FakeFileSystem
			var mkeCmd string

			BeforeEach(func() {
				fakeRunner = fakesys.NewFakeCmdRunner()
				fakeFs = fakesys.NewFakeFileSystem()
				fakeFs.WriteFile("/sys/fs/ext4/features/lazy_itable_init", []byte{})
				fakeRunner.AddCmdResult("blkid -p /dev/xvda2", fakesys.FakeCmdResult{Stdout: `xxxxx TYPE="ext2" yyyy zzzz`})

				mkeCmd = fmt.Sprintf("mke2fs -t %s -j -E lazy_itable_init=1 %s", FileSystemExt4, "/dev/xvda2")
			})

			It("retries mke2fs if the erros is 'device is already in use'", func() {
				fakeRunner.AddCmdResult(mkeCmd, fakesys.FakeCmdResult{
					Error: errors.New(`mke2fs 1.42.9 (4-Feb-2014)
开发者ID:mattcui,项目名称:bosh-agent,代码行数:31,代码来源:linux_formatter_test.go

示例2:

	"strings"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	boshassert "github.com/cloudfoundry/bosh-utils/assert"
	. "github.com/cloudfoundry/bosh-utils/blobstore"
	fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
	fakeuuid "github.com/cloudfoundry/bosh-utils/uuid/fakes"
)

var _ = Describe("externalBlobstore", func() {
	var (
		fs         *fakesys.FakeFileSystem
		runner     *fakesys.FakeCmdRunner
		uuidGen    *fakeuuid.FakeGenerator
		configPath string
		blobstore  Blobstore
	)

	BeforeEach(func() {
		fs = fakesys.NewFakeFileSystem()
		runner = fakesys.NewFakeCmdRunner()
		uuidGen = &fakeuuid.FakeGenerator{}
		configPath = filepath.Join("/etc/", "blobstore-fake-provider.json")
		blobstore = NewExternalBlobstore("fake-provider", map[string]interface{}{}, fs, runner, uuidGen, configPath)
	})

	Describe("Validate", func() {
		It("external validate writes config file", func() {
			options := map[string]interface{}{"fake-key": "fake-value"}
开发者ID:jianqiu,项目名称:bosh-agent,代码行数:31,代码来源:external_blobstore_test.go

示例3:

	BeforeEach(func() {
		mockCtrl = gomock.NewController(GinkgoT())
	})

	AfterEach(func() {
		mockCtrl.Finish()
	})

	var (
		logger                  boshlog.Logger
		compiler                bistatepkg.Compiler
		runner                  *fakesys.FakeCmdRunner
		pkg                     *birelpkg.Package
		fs                      *fakesys.FakeFileSystem
		compressor              *fakecmd.FakeCompressor
		packagesDir             string
		blobstore               *fakeblobstore.FakeBlobstore
		mockCompiledPackageRepo *mock_state_package.MockCompiledPackageRepo

		fakeExtractor *fakeblobextract.FakeExtractor

		dependency1 *birelpkg.Package
		dependency2 *birelpkg.Package
	)

	BeforeEach(func() {
		logger = boshlog.NewLogger(boshlog.LevelNone)
		packagesDir = "fake-packages-dir"
		runner = fakesys.NewFakeCmdRunner()
		fs = fakesys.NewFakeFileSystem()
		compressor = fakecmd.NewFakeCompressor()
开发者ID:mattcui,项目名称:bosh-init,代码行数:31,代码来源:compiler_test.go

示例4:

	fakeaction "github.com/cloudfoundry/bosh-agent/agent/action/fakes"
	"github.com/cloudfoundry/bosh-agent/agent/applier/applyspec"
	. "github.com/cloudfoundry/bosh-agent/agent/script/drain"
	"github.com/cloudfoundry/bosh-agent/agent/script/drain/fakes"
	boshlog "github.com/cloudfoundry/bosh-utils/logger"
	boshsys "github.com/cloudfoundry/bosh-utils/system"
	fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
)

var _ = Describe("ConcreteScript", func() {
	var (
		fs                   *fakesys.FakeFileSystem
		runner               *fakesys.FakeCmdRunner
		params               ScriptParams
		fakeClock            *fakeaction.FakeClock
		script               ConcreteScript
		exampleSpec          func() applyspec.V1ApplySpec
		scriptCommandFactory boshsys.ScriptCommandFactory
	)

	BeforeEach(func() {
		fs = fakesys.NewFakeFileSystem()
		runner = fakesys.NewFakeCmdRunner()
		params = &fakes.FakeScriptParams{}
		fakeClock = &fakeaction.FakeClock{}
		scriptCommandFactory = boshsys.NewScriptCommandFactory("linux")
	})

	JustBeforeEach(func() {
		logger := boshlog.NewLogger(boshlog.LevelNone)
开发者ID:yingkitw,项目名称:bosh-agent,代码行数:30,代码来源:concrete_script_test.go

示例5:

package net_test

import (
	"errors"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	. "github.com/cloudfoundry/bosh-agent/platform/net"
	fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
)

var _ = Describe("cmdRoutesSeacher", func() {
	var (
		runner   *fakesys.FakeCmdRunner
		searcher RoutesSearcher
	)

	BeforeEach(func() {
		runner = fakesys.NewFakeCmdRunner()
		searcher = NewCmdRoutesSearcher(runner)
	})

	Describe("SearchRoutes", func() {
		Context("when running command succeeds", func() {
			It("returns parsed routes information", func() {
				runner.AddCmdResult("route -n", fakesys.FakeCmdResult{
					Stdout: `Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
172.16.79.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
开发者ID:EMC-CMD,项目名称:bosh-agent,代码行数:31,代码来源:cmd_routes_searcher_test.go

示例6:

import (
	"errors"
	"path/filepath"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	boshscript "github.com/cloudfoundry/bosh-agent/agent/script"
	fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
)

var _ = Describe("GenericScript", func() {
	var (
		fs            *fakesys.FakeFileSystem
		cmdRunner     *fakesys.FakeCmdRunner
		genericScript boshscript.GenericScript
		stdoutLogPath string
		stderrLogPath string
	)

	BeforeEach(func() {
		fs = fakesys.NewFakeFileSystem()
		cmdRunner = fakesys.NewFakeCmdRunner()
		stdoutLogPath = filepath.Join("base", "stdout", "logdir", "stdout.log")
		stderrLogPath = filepath.Join("base", "stderr", "logdir", "stderr.log")
		genericScript = boshscript.NewScript(
			fs,
			cmdRunner,
			"my-tag",
			"/path-to-script",
			stdoutLogPath,
开发者ID:EMC-CMD,项目名称:bosh-agent,代码行数:31,代码来源:generic_script_test.go

示例7:

import (
	"errors"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	fakeboshaction "github.com/cloudfoundry/bosh-agent/agent/action/fakes"
	. "github.com/cloudfoundry/bosh-agent/platform/disk"
	boshlog "github.com/cloudfoundry/bosh-utils/logger"
	fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
)

var _ = Describe("PartedPartitioner", func() {
	var (
		fakeCmdRunner *fakesys.FakeCmdRunner
		partitioner   Partitioner
		fakeclock     *fakeboshaction.FakeClock
		logger        boshlog.Logger
	)

	BeforeEach(func() {
		logger = boshlog.NewLogger(boshlog.LevelNone)
		fakeCmdRunner = fakesys.NewFakeCmdRunner()
		fakeclock = &fakeboshaction.FakeClock{}
		partitioner = NewPartedPartitioner(logger, fakeCmdRunner, fakeclock)
	})

	Describe("Partition", func() {
		Context("when the desired partitions do not exist", func() {
			Context("when there is no partition table", func() {
				BeforeEach(func() {
					fakeCmdRunner.AddCmdResult(
开发者ID:jianqiu,项目名称:bosh-agent,代码行数:32,代码来源:parted_partitioner_test.go

示例8: expectedLogFormat

	. "github.com/cloudfoundry/bosh-agent/platform/net/arp"
	boshlog "github.com/cloudfoundry/bosh-utils/logger"
	fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
)

func expectedLogFormat(level, msg string) string {
	return fmt.Sprintf("\\[arp] [0-9]{4}/[0-9]{2}/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} %s - %s\n", level, msg)
}

var _ = Describe("arp", func() {

	var (
		address   string
		arp       Arp
		cmdRunner *fakesys.FakeCmdRunner
		logger    boshlog.Logger
		outBuf    *bytes.Buffer
		errBuf    *bytes.Buffer
	)

	BeforeEach(func() {
		address = "10.0.0.1"
		cmdRunner = fakesys.NewFakeCmdRunner()
		outBuf = bytes.NewBufferString("")
		errBuf = bytes.NewBufferString("")
		logger = boshlog.NewWriterLogger(boshlog.LevelDebug, outBuf, errBuf)
		arp = NewArp(cmdRunner, logger)
	})

	Describe("Delete", func() {
		JustBeforeEach(func() {
开发者ID:teddyking,项目名称:bosh-agent,代码行数:31,代码来源:arp_test.go

示例9:

import (
	"errors"

	. "github.com/cloudfoundry/bosh-init/templatescompiler/erbrenderer"
	fakebierbrenderer "github.com/cloudfoundry/bosh-init/templatescompiler/erbrenderer/fakes"
	boshlog "github.com/cloudfoundry/bosh-utils/logger"
	boshsys "github.com/cloudfoundry/bosh-utils/system"
	fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("ErbRenderer", func() {
	var (
		fs          *fakesys.FakeFileSystem
		runner      *fakesys.FakeCmdRunner
		erbRenderer ERBRenderer
		context     *fakebierbrenderer.FakeTemplateEvaluationContext
	)

	BeforeEach(func() {
		logger := boshlog.NewLogger(boshlog.LevelNone)
		fs = fakesys.NewFakeFileSystem()
		runner = fakesys.NewFakeCmdRunner()
		context = &fakebierbrenderer.FakeTemplateEvaluationContext{}

		erbRenderer = NewERBRenderer(fs, runner, logger)
		fs.TempDirDir = "fake-temp-dir"
	})

	It("constructs ruby erb rendering command", func() {
		err := erbRenderer.Render("fake-src-path", "fake-dst-path", context)
开发者ID:mattcui,项目名称:bosh-init,代码行数:32,代码来源:erb_renderer_test.go

示例10:

package disk_test

import (
	"errors"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	. "github.com/cloudfoundry/bosh-agent/platform/disk"
	fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
)

var _ = Describe("cmdMountsSeacher", func() {
	var (
		runner   *fakesys.FakeCmdRunner
		searcher MountsSearcher
	)

	BeforeEach(func() {
		runner = fakesys.NewFakeCmdRunner()
		searcher = NewCmdMountsSearcher(runner)
	})

	Describe("SearchMounts", func() {
		Context("when running command succeeds", func() {
			It("returns parsed mount information", func() {
				runner.AddCmdResult("mount", fakesys.FakeCmdResult{
					Stdout: `devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
/dev/sda1 on /boot type ext2 (rw)
none on /tmp/warden/cgroup type tmpfs (rw)`,
开发者ID:EMC-CMD,项目名称:bosh-agent,代码行数:31,代码来源:cmd_mounts_searcher_test.go

示例11:

import (
	"errors"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	boshretry "github.com/cloudfoundry/bosh-utils/retrystrategy"
	fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"

	. "github.com/cloudfoundry/bosh-agent/platform"
)

var _ = Describe("MonitRetryable", func() {
	var (
		cmdRunner      *fakesys.FakeCmdRunner
		monitRetryable boshretry.Retryable
	)

	BeforeEach(func() {
		cmdRunner = fakesys.NewFakeCmdRunner()
		monitRetryable = NewMonitRetryable(cmdRunner)
	})

	Describe("Attempt", func() {
		Context("when starting monit fails", func() {
			BeforeEach(func() {
				cmdRunner.AddCmdResult("sv start monit", fakesys.FakeCmdResult{
					ExitStatus: 255,
					Error:      errors.New("fake-start-monit-error"),
				})
			})
开发者ID:EMC-CMD,项目名称:bosh-agent,代码行数:31,代码来源:monit_retryable_test.go

示例12: MACAddresses

	}
	return hw.String()
}

type fakeMACAddressDetector struct {
	macs map[string]string
}

func (m *fakeMACAddressDetector) MACAddresses() (map[string]string, error) {
	return m.macs, nil
}

var _ = Describe("WindowsNetManager", func() {
	var (
		clock                         *fakeclock.FakeClock
		runner                        *fakesys.FakeCmdRunner
		netManager                    Manager
		interfaceConfigurationCreator InterfaceConfigurationCreator
	)
	macAddressDetector := new(fakeMACAddressDetector)

	setupMACs := func(networks ...boshsettings.Network) error {
		m := make(map[string]string)
		for i, net := range networks {
			if net.Mac != "" {
				m[net.Mac] = fmt.Sprintf("Eth_HW %d", i)
			} else {
				m[randomMAC()] = fmt.Sprintf("Eth_Rand %d", i)
			}
		}
		macAddressDetector.macs = m
		return nil
开发者ID:jianqiu,项目名称:bosh-agent,代码行数:32,代码来源:windows_net_manager_test.go

示例13:

/dev/sda3 : start=     xxxx, size= xxxx, Id=83
/dev/sda4 : start=        0, size=    0, Id= 0
`

const devSdaSfdiskDumpOnePartition = `# partition table of /dev/sda
unit: sectors

/dev/sda1 : start=        1, size= xxxx, Id=83
/dev/sda2 : start=     xxxx, size= xxxx, Id=83
/dev/sda3 : start=        0, size=    0, Id= 0
/dev/sda4 : start=        0, size=    0, Id= 0
`

var _ = Describe("sfdiskPartitioner", func() {
	var (
		runner      *fakesys.FakeCmdRunner
		partitioner Partitioner
	)

	BeforeEach(func() {
		runner = fakesys.NewFakeCmdRunner()
		logger := boshlog.NewLogger(boshlog.LevelNone)

		partitioner = NewSfdiskPartitioner(logger, runner)
	})

	It("sfdisk partition", func() {
		runner.AddCmdResult("sfdisk -d /dev/sda", fakesys.FakeCmdResult{Stdout: devSdaSfdiskEmptyDump})

		partitions := []Partition{
			{Type: PartitionTypeSwap, SizeInBytes: 512 * 1024 * 1024},
			{Type: PartitionTypeLinux, SizeInBytes: 1024 * 1024 * 1024},
开发者ID:nimbus-cloud,项目名称:bosh-agent,代码行数:32,代码来源:sfdisk_partitioner_test.go

示例14:

	boshalert "github.com/cloudfoundry/bosh-agent/agent/alert"
	. "github.com/cloudfoundry/bosh-agent/jobsupervisor"
	boshmonit "github.com/cloudfoundry/bosh-agent/jobsupervisor/monit"
	fakemonit "github.com/cloudfoundry/bosh-agent/jobsupervisor/monit/fakes"
	boshdir "github.com/cloudfoundry/bosh-agent/settings/directories"
	boshlog "github.com/cloudfoundry/bosh-utils/logger"
	fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
)

var _ = Describe("monitJobSupervisor", func() {
	var (
		fs                    *fakesys.FakeFileSystem
		runner                *fakesys.FakeCmdRunner
		client                *fakemonit.FakeMonitClient
		logger                boshlog.Logger
		dirProvider           boshdir.Provider
		jobFailuresServerPort int
		monit                 JobSupervisor
	)

	var jobFailureServerPort = 5000

	getJobFailureServerPort := func() int {
		jobFailureServerPort++
		return jobFailureServerPort
	}

	BeforeEach(func() {
		fs = fakesys.NewFakeFileSystem()
		runner = fakesys.NewFakeCmdRunner()
开发者ID:vinodpanicker,项目名称:bosh-agent,代码行数:30,代码来源:monit_job_supervisor_test.go

示例15:

import (
	"errors"
	"os"

	. "github.com/cloudfoundry/bosh-utils/internal/github.com/onsi/ginkgo"
	. "github.com/cloudfoundry/bosh-utils/internal/github.com/onsi/gomega"

	boshlog "github.com/cloudfoundry/bosh-utils/logger"
	. "github.com/cloudfoundry/bosh-utils/system"
	fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
)

var _ = Describe("ScriptRunner", func() {
	var (
		cmdRunner    *fakesys.FakeCmdRunner
		fs           *fakesys.FakeFileSystem
		scriptRunner ScriptRunner
		logger       boshlog.Logger
	)

	BeforeEach(func() {
		scriptCommandFactory := &fakesys.FakeCommandFactory{}
		scriptCommandFactory.ReturnExtension = ".fake-ext"

		cmdRunner = fakesys.NewFakeCmdRunner()

		fs = fakesys.NewFakeFileSystem()

		var err error
		fs.ReturnTempFile, err = fs.OpenFile("/fake-temp-file", os.O_WRONLY, os.ModePerm)
		Expect(err).NotTo(HaveOccurred())
开发者ID:bgandon,项目名称:bosh-utils,代码行数:31,代码来源:script_runner_test.go


注:本文中的github.com/cloudfoundry/bosh-utils/system/fakes.FakeCmdRunner类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。