當前位置: 首頁>>代碼示例>>Golang>>正文


Golang FakeFileSystem.OpenFileErr方法代碼示例

本文整理匯總了Golang中github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem.OpenFileErr方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeFileSystem.OpenFileErr方法的具體用法?Golang FakeFileSystem.OpenFileErr怎麽用?Golang FakeFileSystem.OpenFileErr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem的用法示例。


在下文中一共展示了FakeFileSystem.OpenFileErr方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1:

		})

		Context("when path is a file", func() {
			BeforeEach(func() {
				fs.RegisterOpenFile("/fake-archived-templates-path", &fakesys.FakeFile{
					Contents: []byte("fake-archive-contents"),
					Stats:    &fakesys.FakeFileStats{FileType: fakesys.FakeFileTypeFile},
				})
			})

			It("returns sha1 of the file", func() {
				sha1, err := sha1Calculator.Calculate("/fake-archived-templates-path")
				Expect(err).ToNot(HaveOccurred())
				Expect(sha1).To(Equal("4603db250d7b5b78dfe17869649784353177b549"))
			})
		})

		Context("when reading the file fails", func() {
			BeforeEach(func() {
				fs.OpenFileErr = errors.New("fake-open-file-error")
			})

			It("returns an error", func() {
				_, err := sha1Calculator.Calculate("/fake-archived-templates-path")
				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("fake-open-file-error"))
			})
		})
	})
})
開發者ID:mattcui,項目名稱:bosh-init,代碼行數:30,代碼來源:sha1_calculator_test.go

示例2:

		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:jianqiu,項目名稱:bosh-softlayer-cpi,代碼行數:29,代碼來源:file_test.go

示例3:

			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:EMC-CMD,項目名稱:bosh-agent,代碼行數:31,代碼來源:https_handler_test.go


注:本文中的github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem.OpenFileErr方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。