本文整理匯總了Golang中github.com/cloudfoundry/bosh-utils/system.FileSystem.TempDir方法的典型用法代碼示例。如果您正苦於以下問題:Golang FileSystem.TempDir方法的具體用法?Golang FileSystem.TempDir怎麽用?Golang FileSystem.TempDir使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/bosh-utils/system.FileSystem
的用法示例。
在下文中一共展示了FileSystem.TempDir方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
return fmt.Sprintf("Expected `%s' to not be a directory", actual)
}
var _ = Describe("tarballCompressor", func() {
var (
dstDir string
cmdRunner boshsys.CmdRunner
fs boshsys.FileSystem
compressor Compressor
)
BeforeEach(func() {
logger := boshlog.NewLogger(boshlog.LevelNone)
cmdRunner = boshsys.NewExecCmdRunner(logger)
fs = boshsys.NewOsFileSystem(logger)
tmpDir, err := fs.TempDir("tarballCompressor-test")
Expect(err).NotTo(HaveOccurred())
dstDir = filepath.Join(tmpDir, "TestCompressor")
compressor = NewTarballCompressor(cmdRunner, fs)
})
BeforeEach(func() {
fs.MkdirAll(dstDir, os.ModePerm)
})
AfterEach(func() {
fs.RemoveAll(dstDir)
})
Describe("CompressFilesInDir", func() {
It("compresses the files in the given directory", func() {
示例2:
})
WriteJobConfig := func(configContents WindowsProcessConfig) (string, error) {
dirProvider := boshdirs.NewProvider(basePath)
runner = boshsys.NewExecCmdRunner(logger)
jobSupervisor = NewWindowsJobSupervisor(runner, dirProvider, fs, logger, jobFailuresServerPort,
make(chan bool), DefaultMachineIP)
if err := jobSupervisor.RemoveAllJobs(); err != nil {
return "", err
}
processConfigContents, err := json.Marshal(configContents)
if err != nil {
return "", err
}
jobDir, err = fs.TempDir("testWindowsJobSupervisor")
processConfigPath = filepath.Join(jobDir, "monit")
err = fs.WriteFile(processConfigPath, processConfigContents)
return processConfigPath, err
}
AddJob := func(jobName string) (WindowsProcessConfig, error) {
conf, ok := testWindowsConfigs(jobName)
if !ok {
return conf, fmt.Errorf("Invalid Windows Config Process name: %s", jobName)
}
confPath, err := WriteJobConfig(conf)
if err != nil {
return conf, err
}
示例3:
if (Test-Path %[1]s) {
Remove-Item %[1]s
}`
var tempDir string
var dirProvider boshdir.Provider
var fs boshsys.FileSystem
BeforeEach(func() {
if runtime.GOOS != "windows" {
Skip("Only run on Windows")
}
fs = boshsys.NewOsFileSystem(log)
var err error
tempDir, err = fs.TempDir("")
Expect(err).To(BeNil())
dirProvider = boshdir.NewProvider(tempDir)
certManager = cert.NewWindowsCertManager(fs, boshsys.NewExecCmdRunner(log), dirProvider, log)
})
AfterEach(func() {
for _, thumbprint := range certThumbprints {
cmd := exec.Command("powershell", "-Command", fmt.Sprintf(removeCertScript, `Cert:\LocalMachine\Root\`+thumbprint))
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
Expect(err).To(BeNil())
Eventually(session).Should(gexec.Exit(0))
}
os.RemoveAll(tempDir)
})
示例4:
cmdRunner boshsys.CmdRunner
compressor boshcmd.Compressor
)
BeforeEach(func() {
fs = boshsys.NewOsFileSystem(logger)
cmdRunner = boshsys.NewExecCmdRunner(logger)
compressor = boshcmd.NewTarballCompressor(cmdRunner, fs)
renderedJobListCompressor = NewRenderedJobListCompressor(fs, compressor, fakeSHA1Calculator, logger)
})
It("copies rendered jobs into a new temp dir, compresses the temp dir, and wraps it in a RenderedJobListArchive", func() {
// create rendered job with 2 rendered scripts
renderedJobDir0, err := fs.TempDir("RenderedJobListCompressorTest")
Expect(err).ToNot(HaveOccurred())
renderedJob0 := NewRenderedJob(bireljob.Job{Name: "fake-job-name-0"}, renderedJobDir0, fs, logger)
defer func() { err := renderedJob0.Delete(); Expect(err).ToNot(HaveOccurred()) }()
err = fs.WriteFileString(filepath.Join(renderedJobDir0, "script-0"), "fake-rendered-job-0-script-0-content")
Expect(err).ToNot(HaveOccurred())
err = fs.WriteFileString(filepath.Join(renderedJobDir0, "script-1"), "fake-rendered-job-0-script-1-content")
Expect(err).ToNot(HaveOccurred())
renderedJobList.Add(renderedJob0)
// create another rendered job with 1 rendered script
renderedJobDir1, err := fs.TempDir("RenderedJobListCompressorTest")
Expect(err).ToNot(HaveOccurred())
renderedJob1 := NewRenderedJob(bireljob.Job{Name: "fake-job-name-1"}, renderedJobDir1, fs, logger)
defer func() { err := renderedJob1.Delete(); Expect(err).ToNot(HaveOccurred()) }()
err = fs.WriteFileString(filepath.Join(renderedJobDir1, "script-0"), "fake-rendered-job-1-script-0-content")
示例5:
runStartResponse, err := natsClient.RunStart()
Expect(err).NotTo(HaveOccurred())
Expect(runStartResponse["value"]).To(Equal("started"))
agentState := natsClient.GetState()
Expect(agentState.JobState).To(Equal("running"))
})
It("can run a drain script", func() {
natsClient.PrepareJob("say-hello")
err := natsClient.RunDrain()
Expect(err).NotTo(HaveOccurred())
logsDir, err := fs.TempDir("windows-agent-drain-test")
Expect(err).NotTo(HaveOccurred())
defer fs.RemoveAll(logsDir)
natsClient.FetchLogs(logsDir)
drainLogContents, err := fs.ReadFileString(filepath.Join(logsDir, "say-hello", "drain.log"))
Expect(err).NotTo(HaveOccurred())
Expect(drainLogContents).To(ContainSubstring("Hello from drain"))
})
It("can unmonitor the job during drain script", func() {
natsClient.PrepareJob("unmonitor-hello")
runStartResponse, err := natsClient.RunStart()