github.com/choria-io/go-choria@v0.28.1-0.20240416190746-b3bf9c7d5a45/lifecycle/shutdown_test.go (about) 1 // Copyright (c) 2020-2021, R.I. Pienaar and the Choria Project contributors 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 5 package lifecycle 6 7 import ( 8 . "github.com/onsi/ginkgo/v2" 9 . "github.com/onsi/gomega" 10 ) 11 12 var _ = Describe("ShutdownEvent", func() { 13 Describe("newShutdownEvent", func() { 14 It("Should create the event and set options", func() { 15 event := newShutdownEvent(Component("ginkgo")) 16 Expect(event.Component()).To(Equal("ginkgo")) 17 Expect(event.dtype).To(Equal(Shutdown)) 18 Expect(event.etype).To(Equal("shutdown")) 19 Expect(event.TypeString()).To(Equal("shutdown")) 20 }) 21 }) 22 23 Describe("newShutdownEventFromJSON", func() { 24 It("Should detect invalid protocols", func() { 25 _, err := newShutdownEventFromJSON([]byte(`{"protocol":"x"}`)) 26 Expect(err).To(MatchError("invalid protocol 'x'")) 27 }) 28 29 It("Should parse valid events", func() { 30 event, err := newShutdownEventFromJSON([]byte(`{"protocol":"io.choria.lifecycle.v1.shutdown", "component":"ginkgo"}`)) 31 Expect(err).ToNot(HaveOccurred()) 32 Expect(event.Component()).To(Equal("ginkgo")) 33 Expect(event.dtype).To(Equal(Shutdown)) 34 Expect(event.etype).To(Equal("shutdown")) 35 }) 36 }) 37 })