コード例 #1
0
ファイル: command.go プロジェクト: cloudfoundry/guardian
func (cmd *GuardianCommand) loadProperties(logger lager.Logger, propertiesPath string) (*properties.Manager, error) {
	propManager, err := properties.Load(propertiesPath)
	if err != nil {
		logger.Error("failed-to-load-properties", err, lager.Data{"propertiesPath": propertiesPath})
		return &properties.Manager{}, err
	}

	return propManager, nil
}
コード例 #2
0
	var (
		propPath string
	)

	BeforeEach(func() {
		var err error
		propPath, err = ioutil.TempDir("", "")
		Expect(err).NotTo(HaveOccurred())
	})

	AfterEach(func() {
		Expect(os.RemoveAll(propPath)).To(Succeed())
	})

	It("returns a new manager when the file is not found", func() {
		mgr, err := properties.Load("/path/does/not/exist")
		Expect(err).NotTo(HaveOccurred())
		Expect(mgr).NotTo(BeNil())
	})

	It("save and load the state of the property manager", func() {
		mgr := properties.NewManager()
		mgr.Set("foo", "bar", "baz")

		Expect(properties.Save(path.Join(propPath, "props.json"), mgr)).To(Succeed())
		newMgr, err := properties.Load(path.Join(propPath, "props.json"))
		Expect(err).NotTo(HaveOccurred())

		val, ok := newMgr.Get("foo", "bar")
		Expect(ok).To(BeTrue())
		Expect(val).To(Equal("baz"))