github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/pkg/bindings/test/system_test.go (about)

     1  package test_bindings
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/containers/libpod/pkg/api/handlers"
     7  	"github.com/containers/libpod/pkg/bindings/system"
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  	"github.com/onsi/gomega/gexec"
    11  )
    12  
    13  var _ = Describe("Podman system", func() {
    14  	var (
    15  		bt *bindingTest
    16  		s  *gexec.Session
    17  	)
    18  
    19  	BeforeEach(func() {
    20  		bt = newBindingTest()
    21  		bt.RestoreImagesFromCache()
    22  		s = bt.startAPIService()
    23  		time.Sleep(1 * time.Second)
    24  		err := bt.NewConnection()
    25  		Expect(err).To(BeNil())
    26  	})
    27  
    28  	AfterEach(func() {
    29  		s.Kill()
    30  		bt.cleanup()
    31  	})
    32  
    33  	It("podman events", func() {
    34  		eChan := make(chan handlers.Event, 1)
    35  		var messages []handlers.Event
    36  		cancelChan := make(chan bool, 1)
    37  		go func() {
    38  			for e := range eChan {
    39  				messages = append(messages, e)
    40  			}
    41  		}()
    42  		go func() {
    43  			system.Events(bt.conn, eChan, cancelChan, nil, nil, nil)
    44  		}()
    45  
    46  		_, err := bt.RunTopContainer(nil, nil, nil)
    47  		Expect(err).To(BeNil())
    48  		cancelChan <- true
    49  		Expect(len(messages)).To(BeNumerically("==", 3))
    50  	})
    51  })