-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add tests for gh logger output
Signed-off-by: Felipe Zipitria <[email protected]>
- Loading branch information
Showing
2 changed files
with
57 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package logger | ||
|
||
import ( | ||
"bytes" | ||
"github.com/rs/zerolog" | ||
"github.com/stretchr/testify/suite" | ||
"testing" | ||
) | ||
|
||
type loggerTestSuite struct { | ||
suite.Suite | ||
zl zerolog.Logger | ||
buf *bytes.Buffer | ||
} | ||
|
||
func TestLoggerTestSuite(t *testing.T) { | ||
suite.Run(t, new(loggerTestSuite)) | ||
} | ||
|
||
func (s *loggerTestSuite) SetupSuite() { | ||
s.buf = &bytes.Buffer{} | ||
s.zl = zerolog.New(zerolog.ConsoleWriter{Out: s.buf}).With().Timestamp().Logger() | ||
} | ||
|
||
// TestLogger_Normal tests the normal logger output | ||
func (s *loggerTestSuite) TestLogger_Normal() { | ||
s.zl.Info().Msg("This is a test message") | ||
s.Contains(s.buf.String(), "\x1b[32mINF\x1b[0m This is a test message\n") | ||
s.Equal(52, s.buf.Len()) | ||
s.buf.Reset() | ||
} | ||
|
||
// TestLogger_GitHub tests the GitHub logger output | ||
func (s *loggerTestSuite) TestLogger_GitHub() { | ||
githubLogger := SetGithubOutput(&zerolog.ConsoleWriter{Out: s.buf}) | ||
githubLogger.Info().Msg("This is an info message") | ||
msg, err := s.buf.ReadString('\n') | ||
s.NoError(err) | ||
s.Equal("::notice ::This is an info message\n", msg) | ||
s.Len(msg, 36) | ||
|
||
githubLogger.Debug().Msg("This is a debug message") | ||
msg, err = s.buf.ReadString('\n') | ||
s.NoError(err) | ||
s.Equal("::debug::This is a debug message\n", msg) | ||
} |