firstCommand, secondCommand, }, Distro: provisioner.DistributionPCF, } }) AfterEach(func() { mockCtrl.Finish() }) It("should provision a VM", func() { gomock.InOrder( mockCert.EXPECT().GenerateCerts("some-domain").Return([]byte("some-cert"), []byte("some-key"), []byte("some-ca-cert"), []byte("some-ca-key"), nil), mockFS.EXPECT().Mkdir("/var/vcap/jobs/gorouter/config"), mockFS.EXPECT().Write("/var/vcap/jobs/gorouter/config/cert.pem", bytes.NewReader([]byte("some-cert")), os.FileMode(fs.FileModeRootReadWrite)), mockFS.EXPECT().Write("/var/vcap/jobs/gorouter/config/key.pem", bytes.NewReader([]byte("some-key")), os.FileMode(fs.FileModeRootReadWrite)), mockFS.EXPECT().Mkdir("/var/pcfdev/openssl"), mockFS.EXPECT().Write("/var/pcfdev/openssl/ca_cert.pem", bytes.NewReader([]byte("some-ca-cert")), os.FileMode(fs.FileModeRootReadWrite)), firstCommand.EXPECT().Run(), secondCommand.EXPECT().Run(), mockCmdRunner.EXPECT().Run("some-provision-script-path", "some-domain"), mockFS.EXPECT().Write("/run/pcfdev-healthcheck", bytes.NewReader([]byte("")), os.FileMode(fs.FileModeRootReadWrite)), ) Expect(p.Provision("some-provision-script-path", "some-domain")).To(Succeed()) }) Context("when the distribution is oss", func() { It("should not run pcf 'Commands'", func() {
cmd = &commands.ReplaceDomain{ FS: mockFS, CmdRunner: mockCmdRunner, NewDomain: "some-new-domain", } }) AfterEach(func() { mockCtrl.Finish() }) Describe("#Run", func() { It("should replace the old domain with the new domain in all files (without following symlinks) in /var/vcap/jobs", func() { gomock.InOrder( mockCmdRunner.EXPECT().Output("bash", "-c", "find /var/vcap/jobs/*/ -type f").Return([]byte("/var/vcap/jobs/some-job/some-file\n/var/vcap/jobs/some-job/some-other-file"), nil), mockFS.EXPECT().Read("/var/pcfdev/domain").Return([]byte("some-old-domain\n"), nil), mockCmdRunner.EXPECT().Run("bash", "-c", `perl -p -i -e s/\\Qsome-old-domain\\E/some-new-domain/g /var/vcap/jobs/some-job/some-file /var/vcap/jobs/some-job/some-other-file`), mockFS.EXPECT().Write("/var/pcfdev/domain", strings.NewReader("some-new-domain"), os.FileMode(fs.FileModeRootReadWrite)), ) Expect(cmd.Run()).To(Succeed()) }) Context("when finding job files fails", func() { It("should return an error", func() { mockCmdRunner.EXPECT().Output("bash", "-c", "find /var/vcap/jobs/*/ -type f").Return(nil, errors.New("some-error")) Expect(cmd.Run()).To(MatchError("some-error")) }) })
mockFS = mocks.NewMockFS(mockCtrl) mockCmdRunner = mocks.NewMockCmdRunner(mockCtrl) cmd = &commands.SetupApi{ FS: mockFS, CmdRunner: mockCmdRunner, } }) AfterEach(func() { mockCtrl.Finish() }) Describe("#Run", func() { Context("When the file system is in a bad state", func() { It("returns the error from failing to write the monitrc", func() { mockFS.EXPECT().Write("/var/pcfdev/api/api_ctl", gomock.Any(), os.FileMode(fs.FileModeRootReadWriteExecutable)).AnyTimes() mockFS.EXPECT().Write("/var/vcap/monit/job/1001_pcfdev_api.monitrc", gomock.Any(), os.FileMode(fs.FileModeRootReadWrite)).Return(errors.New("some-error")) Expect(cmd.Run()).To(MatchError("some-error")) }) It("returns the error from failing to write the api_ctl", func() { mockFS.EXPECT().Write("/var/vcap/monit/job/1001_pcfdev_api.monitrc", gomock.Any(), os.FileMode(fs.FileModeRootReadWrite)).AnyTimes() mockFS.EXPECT().Write("/var/pcfdev/api/api_ctl", gomock.Any(), os.FileMode(fs.FileModeRootReadWriteExecutable)).Return(errors.New("some-error")) Expect(cmd.Run()).To(MatchError("some-error")) }) }) It("write a monit file to the /var/vcap/monit/job", func() { monitrc := `check process pcfdev-api