本文整理汇总了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()