func startRedisSession(config restoreconfig.Config, instanceID, planName string) (redisSession *gexec.Session) { var testInstanceDir string testDataDir := config.InstanceDataDir(instanceID) if planName == dedicatedPlan { testInstanceDir = testDataDir os.RemoveAll(testDataDir) } else { testInstanceDir = filepath.Join(config.RedisDataDirectory, instanceID) os.RemoveAll(testInstanceDir) } os.MkdirAll(testDataDir, 0777) err := ioutil.WriteFile( filepath.Join(testInstanceDir, "redis.conf"), []byte("port 6379"), os.ModePerm, ) Expect(err).ToNot(HaveOccurred()) pidfilePath := config.InstancePidFilePath(instanceID) err = os.MkdirAll(config.PidfileDirectory, 0777) Expect(err).NotTo(HaveOccurred()) redisCmd := exec.Command("redis-server", "--dir", testInstanceDir, "--save", "900", "1", "--pidfile", pidfilePath, "--daemonize", "yes", ) redisSession, err = gexec.Start(redisCmd, GinkgoWriter, GinkgoWriter) Expect(err).ToNot(HaveOccurred()) pidFileWritten := make(chan bool) go func(c chan<- bool) { for { if _, err := os.Stat(pidfilePath); !os.IsNotExist(err) { c <- true break } time.Sleep(50 * time.Millisecond) } }(pidFileWritten) // wait for redis to write pid file select { case <-pidFileWritten: break case <-time.After(30 * time.Second): Fail("Test timed out waiting for redis to write PID file.") } return redisSession }
) const ( sharedPlan string = "shared" dedicatedPlan string = "dedicated" ) var _ = Describe("restore", func() { var restoreCommand *exec.Cmd var instanceID string var sourceRdbPath string var redisSession *gexec.Session var monitLogFile string var config restoreconfig.Config BeforeEach(func() { instanceID = "test_instance" sourceRdbPath = filepath.Join("assets", "dump.rdb") err := copyFile(filepath.Join("..", "brokerintegration", "assets", "redis.conf"), "/tmp/redis.conf") Ω(err).ShouldNot(HaveOccurred()) err = copyFile(filepath.Join("assets", "monit"), "/tmp/monit") Ω(err).ShouldNot(HaveOccurred()) err = os.Chmod("/tmp/monit", 0755) Ω(err).ShouldNot(HaveOccurred()) monitLogFile = setupMonitLogFile() }) AfterEach(func() { pid, err := config.InstancePid(instanceID)
package restoreconfig_test import ( "io/ioutil" "os" "path" "github.com/pivotal-cf/cf-redis-broker/restoreconfig" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("Config", func() { var restoreConfig restoreconfig.Config Context("Loads values from restore_config.yml", func() { BeforeEach(func() { var err error restoreConfig, err = restoreconfig.Load(path.Join("assets", "restore-dedicated.yml")) Expect(err).ToNot(HaveOccurred()) }) It("Reads the monit executable", func() { Expect(restoreConfig.MonitExecutablePath).To(Equal("/path/to/monit/file")) }) It("Reads the redis data directory", func() { Expect(restoreConfig.RedisDataDirectory).To(Equal("/tmp/redis/data")) })