コード例 #1
0
func (repo *LocalRepository) WriteConfigFile(instance *Instance) error {
	return redisconf.CopyWithInstanceAdditions(
		repo.RedisConf.DefaultConfigPath,
		repo.InstanceConfigPath(instance.ID),
		instance.ID,
		strconv.Itoa(instance.Port),
		instance.Password,
	)
}
コード例 #2
0
		})
	})

	Describe("CopyWithInstanceAdditions", func() {
		It("writes the instance configuration", func() {
			fromPath, err := filepath.Abs(path.Join("assets", "redis.conf"))
			Expect(err).ToNot(HaveOccurred())

			dir, err := ioutil.TempDir("", "redisconf-test")
			Expect(err).ToNot(HaveOccurred())
			toPath := filepath.Join(dir, "redis.conf")

			instanceID := "an-instance-id"
			port := "1234"
			password := "******"

			err = redisconf.CopyWithInstanceAdditions(fromPath, toPath, instanceID, port, password)
			Ω(err).ToNot(HaveOccurred())

			resultingConf, err := redisconf.Load(toPath)
			Expect(err).ToNot(HaveOccurred())

			Ω(resultingConf.Get("syslog-enabled")).Should(Equal("yes"))
			Ω(resultingConf.Get("syslog-ident")).Should(Equal(fmt.Sprintf("redis-server-%s", instanceID)))
			Ω(resultingConf.Get("syslog-facility")).Should(Equal("local0"))
			Ω(resultingConf.Get("port")).Should(Equal(port))
			Ω(resultingConf.Get("requirepass")).Should(Equal(password))
		})
	})
})