-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from helmwave/tests
feat: add tests
- Loading branch information
Showing
5 changed files
with
188 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: Go Test | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
paths: | ||
- "**.go" | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- "**.go" | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.18 | ||
|
||
- uses: actions/cache@v3 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- name: Install go modules | ||
run: go mod download | ||
|
||
- name: Run tests | ||
run: go test -race -coverprofile=./tests.cov -v -covermode=atomic ./... | ||
|
||
- uses: codecov/[email protected] | ||
with: | ||
files: ./tests.cov | ||
fail_ci_if_error: true |
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,27 @@ | ||
codecov: | ||
require_ci_to_pass: true | ||
|
||
coverage: | ||
precision: 2 | ||
round: down | ||
range: "30...100" | ||
|
||
status: | ||
project: | ||
default: | ||
informational: true # do not fail check | ||
only_pulls: true | ||
patch: false | ||
|
||
parsers: | ||
gcov: | ||
branch_detection: | ||
conditional: yes | ||
loop: yes | ||
method: no | ||
macro: no | ||
|
||
comment: | ||
layout: "reach,diff,flags,files,footer" | ||
behavior: default | ||
require_changes: false |
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,101 @@ | ||
package formatter_test | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
formatter "github.com/helmwave/logrus-emoji-formatter" | ||
"github.com/sirupsen/logrus" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type FormatterTestSuite struct { | ||
suite.Suite | ||
} | ||
|
||
func (s *FormatterTestSuite) createLogger() (*logrus.Logger, *bytes.Buffer) { | ||
logger := logrus.New() | ||
var buf bytes.Buffer | ||
logger.SetFormatter(&formatter.Config{Color: false}) | ||
logger.SetOutput(&buf) | ||
logger.SetLevel(logrus.TraceLevel) | ||
|
||
return logger, &buf | ||
} | ||
|
||
func (s *FormatterTestSuite) TestDefaultFormatting() { | ||
logger, buf := s.createLogger() | ||
|
||
msg := "testblabla" | ||
|
||
s.Run("trace", func() { | ||
expected := fmt.Sprintf("[🤮 aka TRACE]: %s\n", msg) | ||
logger.Trace(msg) | ||
defer buf.Reset() | ||
|
||
s.Require().Equal(expected, buf.String()) | ||
}) | ||
s.Run("debug", func() { | ||
expected := fmt.Sprintf("[🤷 aka DEBUG]: %s\n", msg) | ||
logger.Debug(msg) | ||
defer buf.Reset() | ||
|
||
s.Require().Equal(expected, buf.String()) | ||
}) | ||
s.Run("info", func() { | ||
expected := fmt.Sprintf("[🙃 aka INFO]: %s\n", msg) | ||
logger.Info(msg) | ||
defer buf.Reset() | ||
|
||
s.Require().Equal(expected, buf.String()) | ||
}) | ||
s.Run("warn", func() { | ||
expected := fmt.Sprintf("[🙈 aka WARNING]: %s\n", msg) | ||
logger.Warn(msg) | ||
defer buf.Reset() | ||
|
||
s.Require().Equal(expected, buf.String()) | ||
}) | ||
s.Run("error", func() { | ||
expected := fmt.Sprintf("[💩 aka ERROR]: %s\n", msg) | ||
logger.Error(msg) | ||
defer buf.Reset() | ||
|
||
s.Require().Equal(expected, buf.String()) | ||
}) | ||
} | ||
|
||
func (s *FormatterTestSuite) TestCustomFormat() { | ||
logger, buf := s.createLogger() | ||
|
||
c, _ := logger.Formatter.(*formatter.Config) | ||
c.LogFormat = " " | ||
|
||
msg := "testblabla" | ||
logger.Info(msg) | ||
|
||
s.Require().Equal(" \n", buf.String()) | ||
} | ||
|
||
func (s *FormatterTestSuite) TestTimeFormat() { | ||
logger, buf := s.createLogger() | ||
|
||
c, _ := logger.Formatter.(*formatter.Config) | ||
c.LogFormat = "%time%" | ||
|
||
msg := "testblabla" | ||
expected := time.Now() | ||
logger.Info(msg) | ||
|
||
t, err := time.Parse(time.RFC3339, strings.TrimSpace(buf.String())) | ||
s.Require().NoError(err) | ||
s.Require().WithinDuration(expected, t, time.Second) | ||
} | ||
|
||
func TestFormatterTestSuite(t *testing.T) { | ||
t.Parallel() | ||
suite.Run(t, new(FormatterTestSuite)) | ||
} |
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