github.com/kaituanwang/hyperledger@v2.0.1+incompatible/core/container/build_registry_test.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package container_test
     8  
     9  import (
    10  	"fmt"
    11  
    12  	. "github.com/onsi/ginkgo"
    13  	. "github.com/onsi/gomega"
    14  
    15  	"github.com/hyperledger/fabric/core/container"
    16  )
    17  
    18  var _ = Describe("BuildRegistry", func() {
    19  	var (
    20  		br *container.BuildRegistry
    21  	)
    22  
    23  	BeforeEach(func() {
    24  		br = &container.BuildRegistry{}
    25  	})
    26  
    27  	It("returns a new build status when one does not exist", func() {
    28  		bs, ok := br.BuildStatus("ccid")
    29  		Expect(ok).To(BeFalse())
    30  		Expect(bs).NotTo(BeNil())
    31  		Expect(bs.Done()).NotTo(BeClosed())
    32  	})
    33  
    34  	When("the ccid is already building", func() {
    35  		var (
    36  			initialBS *container.BuildStatus
    37  		)
    38  
    39  		BeforeEach(func() {
    40  			var ok bool
    41  			initialBS, ok = br.BuildStatus("ccid")
    42  			Expect(ok).To(BeFalse())
    43  		})
    44  
    45  		It("returns the existing build status", func() {
    46  			newBS, ok := br.BuildStatus("ccid")
    47  			Expect(ok).To(BeTrue())
    48  			Expect(newBS).To(Equal(initialBS))
    49  		})
    50  	})
    51  })
    52  
    53  var _ = Describe("BuildStatus", func() {
    54  	var (
    55  		bs *container.BuildStatus
    56  	)
    57  
    58  	BeforeEach(func() {
    59  		bs = container.NewBuildStatus()
    60  	})
    61  
    62  	It("has a blocking done channel", func() {
    63  		Expect(bs.Done()).NotTo(BeClosed())
    64  	})
    65  
    66  	When("notify is called with nil", func() {
    67  		BeforeEach(func() {
    68  			bs.Notify(nil)
    69  		})
    70  
    71  		It("closes the blocking done channel", func() {
    72  			Expect(bs.Done()).To(BeClosed())
    73  		})
    74  
    75  		It("leaves err set to nil", func() {
    76  			Expect(bs.Err()).To(BeNil())
    77  		})
    78  	})
    79  
    80  	When("notify is called with an error", func() {
    81  		BeforeEach(func() {
    82  			bs.Notify(fmt.Errorf("fake-error"))
    83  		})
    84  
    85  		It("closes the blocking done channel", func() {
    86  			Expect(bs.Done()).To(BeClosed())
    87  		})
    88  
    89  		It("sets err to the error", func() {
    90  			Expect(bs.Err()).To(MatchError(fmt.Errorf("fake-error")))
    91  		})
    92  	})
    93  })