本文整理匯總了Golang中bosh/system/fakes.FakeFileSystem.WriteToFileError方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeFileSystem.WriteToFileError方法的具體用法?Golang FakeFileSystem.WriteToFileError怎麽用?Golang FakeFileSystem.WriteToFileError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類bosh/system/fakes.FakeFileSystem
的用法示例。
在下文中一共展示了FakeFileSystem.WriteToFileError方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
request, err := http.NewRequest("PUT", serverURL+"/blobs/a5/123-456-789", putPayload)
Expect(err).ToNot(HaveOccurred())
httpResponse, err := httpClient.Do(request)
defer httpResponse.Body.Close()
Expect(err).ToNot(HaveOccurred())
Expect(httpResponse.StatusCode).To(Equal(201))
contents, err := fs.ReadFileString("/var/vcap/micro_bosh/data/cache/123-456-789")
Expect(err).ToNot(HaveOccurred())
Expect(contents).To(Equal("Updated data"))
})
Context("when manager errors", func() {
It("returns a 500", func() {
fs.WriteToFileError = errors.New("oops")
putBody := `Updated data`
putPayload := strings.NewReader(putBody)
waitForServerToStart(serverURL, "blobs", httpClient)
request, err := http.NewRequest("PUT", serverURL+"/blobs/a5/123-456-789", putPayload)
Expect(err).ToNot(HaveOccurred())
httpResponse, err := httpClient.Do(request)
defer httpResponse.Body.Close()
Expect(httpResponse.StatusCode).To(Equal(500))
responseBody, err := ioutil.ReadAll(httpResponse.Body)
Expect(err).ToNot(HaveOccurred())
示例2: init
func init() {
Describe("concreteV1Service", func() {
var (
fs *fakesys.FakeFileSystem
platform *fakeplatform.FakePlatform
specPath = "/spec.json"
service V1Service
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
platform = fakeplatform.NewFakePlatform()
service = NewConcreteV1Service(fs, platform, specPath)
})
Describe("Get", func() {
Context("when filesystem has a spec file", func() {
BeforeEach(func() {
fs.WriteFileString(specPath, `{"deployment":"fake-deployment-name"}`)
})
It("reads spec from filesystem", func() {
spec, err := service.Get()
Expect(err).ToNot(HaveOccurred())
Expect(spec).To(Equal(V1ApplySpec{Deployment: "fake-deployment-name"}))
})
It("returns error if reading spec from filesystem errs", func() {
fs.ReadFileError = errors.New("fake-read-error")
spec, err := service.Get()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-read-error"))
Expect(spec).To(Equal(V1ApplySpec{}))
})
})
Context("when filesystem does not have a spec file", func() {
It("reads spec from filesystem", func() {
spec, err := service.Get()
Expect(err).ToNot(HaveOccurred())
Expect(spec).To(Equal(V1ApplySpec{}))
})
})
})
Describe("Set", func() {
newSpec := V1ApplySpec{Deployment: "fake-deployment-name"}
It("writes spec to filesystem", func() {
err := service.Set(newSpec)
Expect(err).ToNot(HaveOccurred())
specPathStats := fs.GetFileTestStat(specPath)
Expect(specPathStats).ToNot(BeNil())
boshassert.MatchesJSONBytes(GinkgoT(), newSpec, specPathStats.Content)
})
It("returns error if writing spec to filesystem errs", func() {
fs.WriteToFileError = errors.New("fake-write-error")
err := service.Set(newSpec)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-write-error"))
})
})
Describe("ResolveDynamicNetworks", func() {
Context("when there is are no dynamic networks", func() {
unresolvedSpec := V1ApplySpec{
Deployment: "fake-deployment",
NetworkSpecs: map[string]NetworkSpec{
"fake-net": NetworkSpec{
Fields: map[string]interface{}{"ip": "fake-net-ip"},
},
},
}
It("returns spec without modifying any networks", func() {
spec, err := service.ResolveDynamicNetworks(unresolvedSpec)
Expect(err).ToNot(HaveOccurred())
Expect(spec).To(Equal(V1ApplySpec{
Deployment: "fake-deployment",
NetworkSpecs: map[string]NetworkSpec{
"fake-net": NetworkSpec{
Fields: map[string]interface{}{"ip": "fake-net-ip"},
},
},
}))
})
})
Context("when there is one dynamic network", func() {
unresolvedSpec := V1ApplySpec{
Deployment: "fake-deployment",
NetworkSpecs: map[string]NetworkSpec{
"fake-net1": NetworkSpec{
Fields: map[string]interface{}{
"ip": "fake-net1-ip",
"netmask": "fake-net1-netmask",
//.........這裏部分代碼省略.........
示例3: init
//.........這裏部分代碼省略.........
err := manager.AddTaskInfo(boshtask.TaskInfo{
TaskId: "fake-task-id-1",
Method: "fake-method-1",
Payload: []byte("fake-payload-1"),
})
Expect(err).ToNot(HaveOccurred())
err = manager.AddTaskInfo(boshtask.TaskInfo{
TaskId: "fake-task-id-2",
Method: "fake-method-2",
Payload: []byte("fake-payload-2"),
})
Expect(err).ToNot(HaveOccurred())
content, err := fs.ReadFile("/dir/path")
Expect(err).ToNot(HaveOccurred())
var decodedMap map[string]boshtask.TaskInfo
err = json.Unmarshal(content, &decodedMap)
Expect(err).ToNot(HaveOccurred())
Expect(decodedMap).To(Equal(map[string]boshtask.TaskInfo{
"fake-task-id-1": boshtask.TaskInfo{
TaskId: "fake-task-id-1",
Method: "fake-method-1",
Payload: []byte("fake-payload-1"),
},
"fake-task-id-2": boshtask.TaskInfo{
TaskId: "fake-task-id-2",
Method: "fake-method-2",
Payload: []byte("fake-payload-2"),
},
}))
})
It("returns an error when failing to save task", func() {
fs.WriteToFileError = errors.New("fake-write-error")
err := manager.AddTaskInfo(boshtask.TaskInfo{
TaskId: "fake-task-id",
Method: "fake-method",
Payload: []byte("fake-payload"),
})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-write-error"))
})
})
Describe("RemoveTaskInfo", func() {
BeforeEach(func() {
err := manager.AddTaskInfo(boshtask.TaskInfo{
TaskId: "fake-task-id-1",
Method: "fake-method-1",
Payload: []byte("fake-payload-1"),
})
Expect(err).ToNot(HaveOccurred())
err = manager.AddTaskInfo(boshtask.TaskInfo{
TaskId: "fake-task-id-2",
Method: "fake-method-2",
Payload: []byte("fake-payload-2"),
})
Expect(err).ToNot(HaveOccurred())
})
It("removes the task", func() {
err := manager.RemoveTaskInfo("fake-task-id-1")
Expect(err).ToNot(HaveOccurred())
content, err := fs.ReadFile("/dir/path")
Expect(err).ToNot(HaveOccurred())
var decodedMap map[string]boshtask.TaskInfo
err = json.Unmarshal(content, &decodedMap)
Expect(err).ToNot(HaveOccurred())
Expect(decodedMap).To(Equal(map[string]boshtask.TaskInfo{
"fake-task-id-2": boshtask.TaskInfo{
TaskId: "fake-task-id-2",
Method: "fake-method-2",
Payload: []byte("fake-payload-2"),
},
}))
})
It("does not return error when removing task that does not exist", func() {
err := manager.RemoveTaskInfo("fake-unknown-task-id")
Expect(err).ToNot(HaveOccurred())
})
It("returns an error when failing to remove task", func() {
fs.WriteToFileError = errors.New("fake-write-error")
err := manager.RemoveTaskInfo("fake-task-id")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-write-error"))
})
})
})
}
示例4: init
func init() {
Describe("concreteServiceProvider", func() {
var (
platform *fakeplatform.FakePlatform
)
Describe("NewService", func() {
It("returns service with settings.json as its settings path", func() {
// Cannot compare fetcher functions since function comparison is problematic
fs := fakesys.NewFakeFileSystem()
logger := boshlog.NewLogger(boshlog.LevelNone)
service := NewServiceProvider().NewService(fs, "/setting/path", nil, platform, logger)
Expect(service).To(Equal(NewService(fs, "/setting/path/settings.json", nil, platform, logger)))
})
})
})
Describe("concreteService", func() {
var (
fs *fakesys.FakeFileSystem
platform *fakeplatform.FakePlatform
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
platform = fakeplatform.NewFakePlatform()
})
buildService := func(fetcher SettingsFetcher) (Service, *fakesys.FakeFileSystem) {
logger := boshlog.NewLogger(boshlog.LevelNone)
service := NewService(fs, "/setting/path", fetcher, platform, logger)
return service, fs
}
Describe("LoadSettings", func() {
var (
fetchedSettings Settings
fetcherFuncErr error
service Service
)
BeforeEach(func() {
fetchedSettings = Settings{}
fetcherFuncErr = nil
})
JustBeforeEach(func() {
fetcherFunc := func() (Settings, error) { return fetchedSettings, fetcherFuncErr }
service, fs = buildService(fetcherFunc)
})
Context("when settings fetcher succeeds fetching settings", func() {
BeforeEach(func() {
fetchedSettings = Settings{AgentID: "some-new-agent-id"}
})
Context("when settings contain at most one dynamic network", func() {
BeforeEach(func() {
fetchedSettings.Networks = Networks{
"fake-net-1": Network{Type: NetworkTypeDynamic},
}
})
It("updates the service with settings from the fetcher", func() {
err := service.LoadSettings()
Expect(err).NotTo(HaveOccurred())
Expect(service.GetSettings().AgentID).To(Equal("some-new-agent-id"))
})
It("persists settings to the settings file", func() {
err := service.LoadSettings()
Expect(err).NotTo(HaveOccurred())
json, err := json.Marshal(fetchedSettings)
Expect(err).NotTo(HaveOccurred())
fileContent, err := fs.ReadFile("/setting/path")
Expect(err).NotTo(HaveOccurred())
Expect(fileContent).To(Equal(json))
})
It("returns any error from writing to the setting file", func() {
fs.WriteToFileError = errors.New("fs-write-file-error")
err := service.LoadSettings()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fs-write-file-error"))
})
})
Context("when settings contain multiple dynamic networks", func() {
BeforeEach(func() {
fetchedSettings.Networks = Networks{
"fake-net-1": Network{Type: NetworkTypeDynamic},
"fake-net-2": Network{Type: NetworkTypeDynamic},
}
})
It("returns error because multiple dynamic networks are not supported", func() {
err := service.LoadSettings()
//.........這裏部分代碼省略.........
示例5: init
//.........這裏部分代碼省略.........
didHandleAlert = true
return
}
go monit.MonitorJobFailures(failureHandler)
msg := `Hi! How'sit goin`
err := doJobFailureEmail(msg, jobFailuresServerPort)
Expect(err).ToNot(HaveOccurred())
Expect(didHandleAlert).To(BeFalse())
})
Describe("AddJob", func() {
BeforeEach(func() {
fs.WriteFileString("/some/config/path", "fake-config")
})
Context("when reading configuration from config path succeeds", func() {
Context("when writing job configuration succeeds", func() {
It("returns no error because monit can track added job in jobs directory", func() {
err := monit.AddJob("router", 0, "/some/config/path")
Expect(err).ToNot(HaveOccurred())
writtenConfig, err := fs.ReadFileString(
dirProvider.MonitJobsDir() + "/0000_router.monitrc")
Expect(err).ToNot(HaveOccurred())
Expect(writtenConfig).To(Equal("fake-config"))
})
})
Context("when writing job configuration fails", func() {
It("returns error", func() {
fs.WriteToFileError = errors.New("fake-write-error")
err := monit.AddJob("router", 0, "/some/config/path")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-write-error"))
})
})
})
Context("when reading configuration from config path fails", func() {
It("returns error", func() {
fs.ReadFileError = errors.New("fake-read-error")
err := monit.AddJob("router", 0, "/some/config/path")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-read-error"))
})
})
})
Describe("RemoveAllJobs", func() {
Context("when jobs directory removal succeeds", func() {
It("does not return error because all jobs are removed from monit", func() {
jobsDir := dirProvider.MonitJobsDir()
jobBasename := "/0000_router.monitrc"
fs.WriteFileString(jobsDir+jobBasename, "fake-added-job")
err := monit.RemoveAllJobs()
Expect(err).ToNot(HaveOccurred())
Expect(fs.FileExists(jobsDir)).To(BeFalse())
Expect(fs.FileExists(jobsDir + jobBasename)).To(BeFalse())
})
示例6: init
func init() {
Describe("concreteV1Service", func() {
var (
fs *fakesys.FakeFileSystem
specPath = "/spec.json"
service V1Service
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
service = NewConcreteV1Service(fs, specPath)
})
Describe("Get", func() {
Context("when filesystem has a spec file", func() {
BeforeEach(func() {
fs.WriteFileString(specPath, `{"deployment":"fake-deployment-name"}`)
})
It("reads spec from filesystem", func() {
spec, err := service.Get()
Expect(err).ToNot(HaveOccurred())
Expect(spec).To(Equal(V1ApplySpec{Deployment: "fake-deployment-name"}))
})
It("returns error if reading spec from filesystem errs", func() {
fs.ReadFileError = errors.New("fake-read-error")
spec, err := service.Get()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-read-error"))
Expect(spec).To(Equal(V1ApplySpec{}))
})
})
Context("when filesystem does not have a spec file", func() {
It("reads spec from filesystem", func() {
spec, err := service.Get()
Expect(err).ToNot(HaveOccurred())
Expect(spec).To(Equal(V1ApplySpec{}))
})
})
})
Describe("Set", func() {
newSpec := V1ApplySpec{Deployment: "fake-deployment-name"}
It("writes spec to filesystem", func() {
err := service.Set(newSpec)
Expect(err).ToNot(HaveOccurred())
specPathStats := fs.GetFileTestStat(specPath)
Expect(specPathStats).ToNot(BeNil())
boshassert.MatchesJSONBytes(GinkgoT(), newSpec, specPathStats.Content)
})
It("returns error if writing spec to filesystem errs", func() {
fs.WriteToFileError = errors.New("fake-write-error")
err := service.Set(newSpec)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-write-error"))
})
})
Describe("PopulateDynamicNetworks", func() {
Context("when there are no dynamic networks", func() {
unresolvedSpec := V1ApplySpec{
Deployment: "fake-deployment",
NetworkSpecs: map[string]NetworkSpec{
"fake-net": NetworkSpec{
Fields: map[string]interface{}{"ip": "fake-net-ip"},
},
},
}
It("returns spec without modifying any networks", func() {
spec, err := service.PopulateDynamicNetworks(unresolvedSpec, boshsettings.Settings{})
Expect(err).ToNot(HaveOccurred())
Expect(spec).To(Equal(V1ApplySpec{
Deployment: "fake-deployment",
NetworkSpecs: map[string]NetworkSpec{
"fake-net": NetworkSpec{
Fields: map[string]interface{}{"ip": "fake-net-ip"},
},
},
}))
})
})
Context("when there are dynamic networks", func() {
unresolvedSpec := V1ApplySpec{
Deployment: "fake-deployment",
NetworkSpecs: map[string]NetworkSpec{
"fake-net1": NetworkSpec{
Fields: map[string]interface{}{
"ip": "fake-net1-ip",
"netmask": "fake-net1-netmask",
"gateway": "fake-net1-gateway",
},
//.........這裏部分代碼省略.........
示例7: init
func init() {
Describe("concreteV1Service", func() {
var (
fs *fakesys.FakeFileSystem
specPath string
service V1Service
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
specPath = "/spec.json"
service = NewConcreteV1Service(fs, specPath)
})
Describe("Get", func() {
Context("when filesystem has a spec file", func() {
BeforeEach(func() {
fs.WriteFileString(specPath, `{"deployment":"fake-deployment-name"}`)
})
It("reads spec from filesystem", func() {
spec, err := service.Get()
Expect(err).ToNot(HaveOccurred())
Expect(spec).To(Equal(V1ApplySpec{Deployment: "fake-deployment-name"}))
})
It("returns error if reading spec from filesystem errs", func() {
fs.ReadFileError = errors.New("fake-read-error")
spec, err := service.Get()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-read-error"))
Expect(spec).To(Equal(V1ApplySpec{}))
})
})
Context("when filesystem does not have a spec file", func() {
It("reads spec from filesystem", func() {
spec, err := service.Get()
Expect(err).ToNot(HaveOccurred())
Expect(spec).To(Equal(V1ApplySpec{}))
})
})
})
Describe("Set", func() {
newSpec := V1ApplySpec{Deployment: "fake-deployment-name"}
It("writes spec to filesystem", func() {
err := service.Set(newSpec)
Expect(err).ToNot(HaveOccurred())
specPathStats := fs.GetFileTestStat(specPath)
Expect(specPathStats).ToNot(BeNil())
boshassert.MatchesJSONBytes(GinkgoT(), newSpec, specPathStats.Content)
})
It("returns error if writing spec to filesystem errs", func() {
fs.WriteToFileError = errors.New("fake-write-error")
err := service.Set(newSpec)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-write-error"))
})
})
})
}
示例8:
Context("when reading configuration from config path succeeds", func() {
Context("when writing job configuration succeeds", func() {
It("returns no error because monit can track added job in jobs directory", func() {
err := monit.AddJob("router", 0, "/some/config/path")
Expect(err).ToNot(HaveOccurred())
writtenConfig, err := fs.ReadFileString(
dirProvider.MonitJobsDir() + "/0000_router.monitrc")
Expect(err).ToNot(HaveOccurred())
Expect(writtenConfig).To(Equal("fake-config"))
})
})
Context("when writing job configuration fails", func() {
It("returns error", func() {
fs.WriteToFileError = errors.New("fake-write-error")
err := monit.AddJob("router", 0, "/some/config/path")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-write-error"))
})
})
})
Context("when reading configuration from config path fails", func() {
It("returns error", func() {
fs.ReadFileError = errors.New("fake-read-error")
err := monit.AddJob("router", 0, "/some/config/path")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-read-error"))