github.com/mongodb/grip@v0.0.0-20240213223901-f906268d82b9/journaling_test.go (about)

     1  package grip
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/mongodb/grip/send"
     7  	"github.com/stretchr/testify/suite"
     8  )
     9  
    10  type GripSuite struct {
    11  	grip Journaler
    12  	name string
    13  	suite.Suite
    14  }
    15  
    16  func TestGripSuite(t *testing.T) {
    17  	suite.Run(t, new(GripSuite))
    18  }
    19  
    20  func (s *GripSuite) SetupSuite() {
    21  	s.grip = NewJournaler(s.name)
    22  	s.Equal(s.grip.Name(), s.name)
    23  }
    24  
    25  func (s *GripSuite) SetupTest() {
    26  	s.grip.SetName(s.name)
    27  	sender, err := send.NewNativeLogger(s.name, s.grip.GetSender().Level())
    28  	s.NoError(err)
    29  	s.NoError(s.grip.SetSender(sender))
    30  }
    31  
    32  func (s *GripSuite) TestDefaultJournalerIsBootstrap() {
    33  	firstName := s.grip.Name()
    34  	// the bootstrap sender is a bit special because you can't
    35  	// change it's name, therefore:
    36  	secondName := "something_else"
    37  	s.grip.SetName(secondName)
    38  
    39  	s.Equal(s.grip.Name(), secondName)
    40  	s.NotEqual(s.grip.Name(), firstName)
    41  	s.NotEqual(firstName, secondName)
    42  }
    43  
    44  func (s *GripSuite) TestNameSetterAndGetter() {
    45  	for _, name := range []string{"a", "a39df", "a@)(*E)"} {
    46  		s.grip.SetName(name)
    47  		s.Equal(s.grip.Name(), name)
    48  	}
    49  }