github.com/ahlemtn/fabric@v2.1.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  	When("a previous build status had an error", func() {
    53  		BeforeEach(func() {
    54  			bs, ok := br.BuildStatus("ccid")
    55  			Expect(ok).To(BeFalse())
    56  			Expect(bs).NotTo(BeNil())
    57  			bs.Notify(fmt.Errorf("fake-error"))
    58  			Expect(bs.Done()).To(BeClosed())
    59  			Expect(bs.Err()).To(MatchError(fmt.Errorf("fake-error")))
    60  		})
    61  
    62  		It("can be reset", func() {
    63  			bs := br.ResetBuildStatus("ccid")
    64  			Expect(bs).NotTo(BeNil())
    65  			Expect(bs.Done()).NotTo(BeClosed())
    66  			Expect(bs.Err()).To(BeNil())
    67  		})
    68  	})
    69  })
    70  
    71  var _ = Describe("BuildStatus", func() {
    72  	var (
    73  		bs *container.BuildStatus
    74  	)
    75  
    76  	BeforeEach(func() {
    77  		bs = container.NewBuildStatus()
    78  	})
    79  
    80  	It("has a blocking done channel", func() {
    81  		Expect(bs.Done()).NotTo(BeClosed())
    82  	})
    83  
    84  	When("notify is called with nil", func() {
    85  		BeforeEach(func() {
    86  			bs.Notify(nil)
    87  		})
    88  
    89  		It("closes the blocking done channel", func() {
    90  			Expect(bs.Done()).To(BeClosed())
    91  		})
    92  
    93  		It("leaves err set to nil", func() {
    94  			Expect(bs.Err()).To(BeNil())
    95  		})
    96  	})
    97  
    98  	When("notify is called with an error", func() {
    99  		BeforeEach(func() {
   100  			bs.Notify(fmt.Errorf("fake-error"))
   101  		})
   102  
   103  		It("closes the blocking done channel", func() {
   104  			Expect(bs.Done()).To(BeClosed())
   105  		})
   106  
   107  		It("sets err to the error", func() {
   108  			Expect(bs.Err()).To(MatchError(fmt.Errorf("fake-error")))
   109  		})
   110  	})
   111  })