github.com/choria-io/go-choria@v0.28.1-0.20240416190746-b3bf9c7d5a45/providers/agent/mcorpc/ruby/util_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 ruby
     6  
     7  import (
     8  	"io"
     9  	"os"
    10  	"testing"
    11  
    12  	. "github.com/onsi/ginkgo/v2"
    13  	. "github.com/onsi/gomega"
    14  	"github.com/sirupsen/logrus"
    15  )
    16  
    17  func Test(t *testing.T) {
    18  	os.Setenv("MCOLLECTIVE_CERTNAME", "rip.mcollective")
    19  	RegisterFailHandler(Fail)
    20  	RunSpecs(t, "Providers/Agent/McoRPC/Ruby")
    21  }
    22  
    23  var _ = Describe("McoRPC/Ruby", func() {
    24  	var logger *logrus.Entry
    25  
    26  	BeforeEach(func() {
    27  		l := logrus.New()
    28  		l.Out = io.Discard
    29  		logger = l.WithFields(logrus.Fields{})
    30  	})
    31  
    32  	var _ = Describe("Provider", func() {
    33  		var _ = Describe("shouldLoadAgent", func() {
    34  			It("Should not load agents in the deny list", func() {
    35  				Expect(shouldLoadAgent("rpcutil")).To(BeFalse())
    36  				Expect(shouldLoadAgent("choria_util")).To(BeFalse())
    37  				Expect(shouldLoadAgent("discovery")).To(BeFalse())
    38  				Expect(shouldLoadAgent("foo")).To(BeTrue())
    39  			})
    40  		})
    41  
    42  		var _ = Describe("loadAgents", func() {
    43  			It("Should load only ruby agents in all libdirs", func() {
    44  				p := Provider{
    45  					log: logger,
    46  				}
    47  
    48  				p.loadAgents([]string{"testdata/lib1", "testdata/lib2"})
    49  
    50  				Expect(p.Agents()).To(HaveLen(2))
    51  				Expect(p.Agents()[0].Metadata.Name).To(Equal("one"))
    52  				Expect(p.Agents()[1].Metadata.Name).To(Equal("two"))
    53  			})
    54  		})
    55  	})
    56  })