github.com/cloudfoundry-attic/garden-linux@v0.333.2-candidate/hook/hooks_test.go (about)

     1  package hook_test
     2  
     3  import (
     4  	"github.com/cloudfoundry-incubator/garden-linux/hook"
     5  
     6  	. "github.com/onsi/ginkgo"
     7  	. "github.com/onsi/gomega"
     8  )
     9  
    10  var _ = Describe("HookSet", func() {
    11  	var registry hook.HookSet
    12  
    13  	BeforeEach(func() {
    14  		registry = make(hook.HookSet)
    15  	})
    16  
    17  	Context("when the first argument names a registered hook", func() {
    18  		It("runs the hook", func() {
    19  			wasRun := false
    20  			registry.Register("a-hook", func() {
    21  				wasRun = true
    22  			})
    23  
    24  			registry.Main("a-hook")
    25  			Expect(wasRun).To(BeTrue())
    26  		})
    27  	})
    28  
    29  	Context("when the first argument does not name a registered hook", func() {
    30  		It("panics", func() {
    31  			Expect(func() { registry.Main("does-not-hook") }).To(Panic())
    32  		})
    33  	})
    34  
    35  	Context("when multiple hooks are registered with the same name", func() {
    36  		It("panics", func() {
    37  			registry.Register("a-hook", func() {})
    38  			Expect(func() { registry.Register("a-hook", func() {}) }).To(Panic())
    39  		})
    40  	})
    41  })