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


Golang FakeFileSystem.OpenFileErr方法代码示例

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


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

示例1:

			Expect(runScriptResult.Tag).To(Equal("my-tag"))
			Expect(runScriptResult.Error).To(BeNil())
		})

		It("returns an error if it fails to create logs directory", func() {
			fs.MkdirAllError = errors.New("fake-mkdir-all-error")

			runScriptResult := genericScript.Run()

			Expect(runScriptResult.Tag).To(Equal("my-tag"))
			Expect(runScriptResult.Error.Error()).To(Equal("fake-mkdir-all-error"))
		})

		It("returns an error if it fails to open stdout/stderr log file", func() {
			fs.OpenFileErr = errors.New("fake-open-file-error")

			runScriptResult := genericScript.Run()

			Expect(runScriptResult.Tag).To(Equal("my-tag"))
			Expect(runScriptResult.Error.Error()).To(Equal("fake-open-file-error"))
		})

		Context("when command succeeds", func() {

			BeforeEach(func() {
				cmdRunner.AddCmdResult("/path-to-script", fakesys.FakeCmdResult{
					Stdout:     "fake-stdout",
					Stderr:     "fake-stderr",
					ExitStatus: 0,
					Error:      nil,
开发者ID:gu-bin,项目名称:bosh-agent,代码行数:30,代码来源:generic_script_test.go

示例2:

			It("returns a 404", func() {
				postBody := `{"method":"ping","arguments":["foo","bar"], "reply_to": "reply to me!"}`
				postPayload := strings.NewReader(postBody)

				httpResponse, err := httpClient.Post(serverURL+"/blobs/123", "application/json", postPayload)
				Expect(err).ToNot(HaveOccurred())

				defer httpResponse.Body.Close()

				Expect(httpResponse.StatusCode).To(Equal(404))
			})
		})

		Context("when file does not exist", func() {
			It("returns a 404", func() {
				fs.OpenFileErr = errors.New("no such file or directory")
				httpResponse, err := httpClient.Get(serverURL + "/blobs/123")
				Expect(err).ToNot(HaveOccurred())

				defer httpResponse.Body.Close()
				Expect(httpResponse.StatusCode).To(Equal(404))
			})
		})

		Context("when file does not have correct permissions", func() {
			It("returns a 500", func() {
				fs.OpenFileErr = errors.New("permission denied")
				httpResponse, err := httpClient.Get(serverURL + "/blobs/123")
				Expect(err).ToNot(HaveOccurred())

				defer httpResponse.Body.Close()
开发者ID:pivotal-nader-ziada,项目名称:bosh-agent,代码行数:31,代码来源:https_handler_test.go

示例3:

		logger.Error("TAG", "some %s info to log", "awesome")

		contents, err := fs.ReadFileString(logFile.Name())
		Expect(err).ToNot(HaveOccurred())

		expectedContent := expectedLogFormat("TAG", "ERROR - some awesome info to log")
		Expect(contents).To(MatchRegexp(expectedContent))
	})

	It("does not log at NONE level", func() {
		logger, logFile, err := New(boshlog.LevelNone, logFile.Name(), DefaultLogFileMode, fs)
		Expect(err).ToNot(HaveOccurred())

		logger.Error("TAG", "some %s info to log", "awesome")

		contents, err := fs.ReadFileString(logFile.Name())
		Expect(err).ToNot(HaveOccurred())

		Expect(contents).To(Equal(""))
	})

	It("errors if the file cannot be openned for writing", func() {
		fs.OpenFileErr = errors.New("fake-fs-error")

		_, _, err := New(boshlog.LevelNone, logFile.Name(), DefaultLogFileMode, fs)
		Expect(err).To(HaveOccurred())
		Expect(err.Error()).To(ContainSubstring("fake-fs-error"))
	})
})
开发者ID:viovanov,项目名称:bosh-agent,代码行数:29,代码来源:file_test.go


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