コード例 #1
0
	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
0
		})

		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
0
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
0
				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
0
ファイル: windows_test.go プロジェクト: mattcui/bosh-init
		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()