本文整理匯總了Golang中github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/uuid/fakes.FakeGenerator類的典型用法代碼示例。如果您正苦於以下問題:Golang FakeGenerator類的具體用法?Golang FakeGenerator怎麽用?Golang FakeGenerator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了FakeGenerator類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
. "github.com/cloudfoundry/bosh-agent/internal/github.com/onsi/gomega"
. "github.com/cloudfoundry/bosh-agent/agent/alert"
fakeuuid "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/uuid/fakes"
"github.com/cloudfoundry/bosh-agent/internal/github.com/pivotal-golang/clock/fakeclock"
fakesettings "github.com/cloudfoundry/bosh-agent/settings/fakes"
boshlog "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/logger"
boshsyslog "github.com/cloudfoundry/bosh-agent/syslog"
)
var _ = Describe("sshAdapter", func() {
var (
settingsService *fakesettings.FakeSettingsService
timeService *fakeclock.FakeClock
logger boshlog.Logger
uuidGenerator *fakeuuid.FakeGenerator
)
BeforeEach(func() {
settingsService = &fakesettings.FakeSettingsService{}
timeService = fakeclock.NewFakeClock(time.Now())
logger = boshlog.NewLogger(boshlog.LevelNone)
uuidGenerator = &fakeuuid.FakeGenerator{}
})
Describe("IsIgnorable", func() {
itDoesNotIgnore := func(msgContent string) {
sshMsg := boshsyslog.Msg{Content: msgContent}
sshAdapter := NewSSHAdapter(
示例2: init
func init() {
Describe("asyncTaskService", func() {
var (
uuidGen *fakeuuid.FakeGenerator
service Service
)
BeforeEach(func() {
uuidGen = &fakeuuid.FakeGenerator{}
service = NewAsyncTaskService(uuidGen, boshlog.NewLogger(boshlog.LevelNone))
})
Describe("StartTask", func() {
startAndWaitForTaskCompletion := func(task Task) Task {
service.StartTask(task)
for task.State == StateRunning {
time.Sleep(time.Nanosecond)
task, _ = service.FindTaskWithID(task.ID)
}
return task
}
It("sets return value on a successful task", func() {
runFunc := func() (interface{}, error) { return 123, nil }
task, err := service.CreateTask(runFunc, nil, nil)
Expect(err).ToNot(HaveOccurred())
task = startAndWaitForTaskCompletion(task)
Expect(task.State).To(BeEquivalentTo(StateDone))
Expect(task.Value).To(Equal(123))
Expect(task.Error).To(BeNil())
})
It("sets task error on a failing task", func() {
err := errors.New("fake-error")
runFunc := func() (interface{}, error) { return nil, err }
task, createErr := service.CreateTask(runFunc, nil, nil)
Expect(createErr).ToNot(HaveOccurred())
task = startAndWaitForTaskCompletion(task)
Expect(task.State).To(BeEquivalentTo(StateFailed))
Expect(task.Value).To(BeNil())
Expect(task.Error).To(Equal(err))
})
Describe("CreateTask", func() {
It("can run task created with CreateTask which does not have end func", func() {
ranFunc := false
runFunc := func() (interface{}, error) { ranFunc = true; return nil, nil }
task, err := service.CreateTask(runFunc, nil, nil)
Expect(err).ToNot(HaveOccurred())
startAndWaitForTaskCompletion(task)
Expect(ranFunc).To(BeTrue())
})
It("can run task created with CreateTask which has end func", func() {
ranFunc := false
runFunc := func() (interface{}, error) { ranFunc = true; return nil, nil }
ranEndFunc := false
endFunc := func(Task) { ranEndFunc = true }
task, err := service.CreateTask(runFunc, nil, endFunc)
Expect(err).ToNot(HaveOccurred())
startAndWaitForTaskCompletion(task)
Expect(ranFunc).To(BeTrue())
Expect(ranEndFunc).To(BeTrue())
})
It("returns an error if generate uuid fails", func() {
uuidGen.GenerateError = errors.New("fake-generate-uuid-error")
_, err := service.CreateTask(nil, nil, nil)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-generate-uuid-error"))
})
})
Describe("CreateTaskWithID", func() {
It("can run task created with CreateTaskWithID which does not have end func", func() {
ranFunc := false
runFunc := func() (interface{}, error) { ranFunc = true; return nil, nil }
task := service.CreateTaskWithID("fake-task-id", runFunc, nil, nil)
startAndWaitForTaskCompletion(task)
Expect(ranFunc).To(BeTrue())
})
It("can run task created with CreateTaskWithID which has end func", func() {
ranFunc := false
runFunc := func() (interface{}, error) { ranFunc = true; return nil, nil }
ranEndFunc := false
endFunc := func(Task) { ranEndFunc = true }
//.........這裏部分代碼省略.........
示例3:
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
boshassert "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/assert"
. "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/blobstore"
fakesys "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system/fakes"
fakeuuid "github.com/cloudfoundry/bosh-agent/internal/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"}
示例4:
import (
"errors"
"os"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/blobstore"
fakesys "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system/fakes"
fakeuuid "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/uuid/fakes"
)
var _ = Describe("localBlobstore", func() {
var (
fs *fakesys.FakeFileSystem
uuidGen *fakeuuid.FakeGenerator
fakeBlobstorePath = "/some/local/path"
blobstore Blobstore
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
uuidGen = &fakeuuid.FakeGenerator{}
options := map[string]interface{}{"blobstore_path": fakeBlobstorePath}
blobstore = NewLocalBlobstore(fs, uuidGen, options)
})
Describe("Validate", func() {
It("returns no error when blobstore_path is present", func() {
err := blobstore.Validate()
Expect(err).ToNot(HaveOccurred())
})
示例5: init
func init() {
Describe("Agent", func() {
var (
logger boshlog.Logger
handler *fakembus.FakeHandler
platform *fakeplatform.FakePlatform
actionDispatcher *fakeagent.FakeActionDispatcher
jobSupervisor *fakejobsuper.FakeJobSupervisor
specService *fakeas.FakeV1Service
syslogServer *fakesyslog.FakeServer
settingsService *fakesettings.FakeSettingsService
uuidGenerator *fakeuuid.FakeGenerator
timeService *fakeclock.FakeClock
agent Agent
)
BeforeEach(func() {
logger = boshlog.NewLogger(boshlog.LevelNone)
handler = &fakembus.FakeHandler{}
platform = fakeplatform.NewFakePlatform()
actionDispatcher = &fakeagent.FakeActionDispatcher{}
jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
specService = fakeas.NewFakeV1Service()
syslogServer = &fakesyslog.FakeServer{}
settingsService = &fakesettings.FakeSettingsService{}
uuidGenerator = &fakeuuid.FakeGenerator{}
timeService = fakeclock.NewFakeClock(time.Now())
agent = New(
logger,
handler,
platform,
actionDispatcher,
jobSupervisor,
specService,
syslogServer,
5*time.Millisecond,
settingsService,
uuidGenerator,
timeService,
)
})
Describe("Run", func() {
It("lets dispatcher handle requests arriving via handler", func() {
err := agent.Run()
Expect(err).ToNot(HaveOccurred())
expectedResp := boshhandler.NewValueResponse("pong")
actionDispatcher.DispatchResp = expectedResp
req := boshhandler.NewRequest("fake-reply", "fake-action", []byte("fake-payload"))
resp := handler.RunFunc(req)
Expect(actionDispatcher.DispatchReq).To(Equal(req))
Expect(resp).To(Equal(expectedResp))
})
It("resumes persistent actions *before* dispatching new requests", func() {
resumedBeforeStartingToDispatch := false
handler.RunCallBack = func() {
resumedBeforeStartingToDispatch = actionDispatcher.ResumedPreviouslyDispatchedTasks
}
err := agent.Run()
Expect(err).ToNot(HaveOccurred())
Expect(resumedBeforeStartingToDispatch).To(BeTrue())
})
Context("when heartbeats can be sent", func() {
BeforeEach(func() {
handler.KeepOnRunning()
})
BeforeEach(func() {
jobName := "fake-job"
jobIndex := 1
specService.Spec = boshas.V1ApplySpec{
JobSpec: boshas.JobSpec{Name: &jobName},
Index: &jobIndex,
}
jobSupervisor.StatusStatus = "fake-state"
platform.FakeVitalsService.GetVitals = boshvitals.Vitals{
Load: []string{"a", "b", "c"},
}
})
expectedJobName := "fake-job"
expectedJobIndex := 1
expectedHb := Heartbeat{
Job: &expectedJobName,
Index: &expectedJobIndex,
JobState: "fake-state",
Vitals: boshvitals.Vitals{Load: []string{"a", "b", "c"}},
}
It("sends initial heartbeat", func() {
// Configure periodic heartbeat every 5 hours
// so that we are sure that we will not receive it
//.........這裏部分代碼省略.........