mockCmdRunner = mocks.NewMockCmdRunner(mockCtrl) 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")) }) })
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() { p.Distro = provisioner.DistributionOSS 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)),