github.com/cloudfoundry-attic/ltc@v0.0.0-20151123212628-098adc7919fc/config/persister/mem_persister_test.go (about)

     1  package persister_test
     2  
     3  import (
     4  	. "github.com/onsi/ginkgo"
     5  	. "github.com/onsi/gomega"
     6  
     7  	"github.com/cloudfoundry-incubator/ltc/config/persister"
     8  )
     9  
    10  var _ = Describe("MemPersister", func() {
    11  	type data struct {
    12  		Value string
    13  	}
    14  
    15  	type dataTwo struct {
    16  		OtherValue string
    17  	}
    18  
    19  	It("Loads and Saves data in memory", func() {
    20  		memPersister := persister.NewMemPersister()
    21  
    22  		dataToSave := &data{Value: "Save?"}
    23  		err := memPersister.Save(dataToSave)
    24  		Expect(err).ToNot(HaveOccurred())
    25  
    26  		dataToLoad := &data{}
    27  		err = memPersister.Load(dataToLoad)
    28  		Expect(err).ToNot(HaveOccurred())
    29  
    30  		Expect(dataToLoad.Value).To(Equal("Save?"))
    31  	})
    32  
    33  	It("returns errors when using complex types", func() {
    34  		memPersister := persister.NewMemPersister()
    35  
    36  		err := memPersister.Save(func() {})
    37  		Expect(err).To(HaveOccurred())
    38  
    39  		err = memPersister.Load(func() {})
    40  		Expect(err).To(HaveOccurred())
    41  	})
    42  })