github.com/choria-io/go-choria@v0.28.1-0.20240416190746-b3bf9c7d5a45/providers/ddlresolver/internal_cache_test.go (about) 1 // Copyright (c) 2021, R.I. Pienaar and the Choria Project contributors 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 5 package ddlresolver 6 7 import ( 8 "context" 9 10 imock "github.com/choria-io/go-choria/inter/imocks" 11 "github.com/choria-io/go-choria/internal/fs" 12 agentDDL "github.com/choria-io/go-choria/providers/agent/mcorpc/ddl/agent" 13 "github.com/golang/mock/gomock" 14 . "github.com/onsi/ginkgo/v2" 15 . "github.com/onsi/gomega" 16 ) 17 18 var _ = Describe("InternalCachedDDLResolver", func() { 19 var ( 20 res *InternalCachedDDLResolver 21 fw *imock.MockFramework 22 mockctl *gomock.Controller 23 ) 24 25 BeforeEach(func() { 26 mockctl = gomock.NewController(GinkgoT()) 27 fw, _ = imock.NewFrameworkForTests(mockctl, GinkgoWriter) 28 res = &InternalCachedDDLResolver{} 29 }) 30 31 AfterEach(func() { 32 mockctl.Finish() 33 }) 34 35 Describe("DDL", func() { 36 It("Should handle failures", func() { 37 err := res.DDL(context.Background(), "foo", "bar", nil, fw) 38 Expect(err).To(MatchError("unsupported ddl type \"foo\"")) 39 }) 40 41 It("Should correctly find and unmarshal into target", func() { 42 ddl := &agentDDL.DDL{} 43 err := res.DDL(context.Background(), "agent", "choria_util", ddl, fw) 44 Expect(err).ToNot(HaveOccurred()) 45 Expect(ddl.Metadata.Name).To(Equal("choria_util")) 46 }) 47 }) 48 49 Describe("DDLBytes", func() { 50 It("Should handle failures", func() { 51 _, err := res.DDLBytes(context.Background(), "foo", "bar", fw) 52 Expect(err).To(MatchError("unsupported ddl type \"foo\"")) 53 }) 54 55 It("Should find the correct DDL", func() { 56 b, err := res.DDLBytes(context.Background(), "agent", "choria_util", fw) 57 Expect(err).ToNot(HaveOccurred()) 58 expected, err := fs.FS.ReadFile("ddl/cache/agent/choria_util.json") 59 Expect(err).ToNot(HaveOccurred()) 60 Expect(expected).ToNot(BeEmpty()) 61 Expect(b).To(Equal(expected)) 62 }) 63 }) 64 65 Describe("DDLNames", func() { 66 It("Should handle failures", func() { 67 _, err := res.DDLBytes(context.Background(), "foo", "bar", fw) 68 Expect(err).To(MatchError("unsupported ddl type \"foo\"")) 69 }) 70 71 It("Should find the correct names", func() { 72 names, err := res.DDLNames(context.Background(), "agent", fw) 73 Expect(err).ToNot(HaveOccurred()) 74 Expect(names).To(Equal([]string{"aaa_signer", "choria_provision", "choria_registry", "choria_util", "rpcutil", "scout"})) 75 }) 76 }) 77 })