mirror of
https://github.com/git-chglog/git-chglog.git
synced 2026-01-22 18:06:11 +00:00
BREAKING CHANGE: `JiraIssueId` has been renamed to `JiraIssueID`. This impacts the value for `pattern_maps` in `config.yml`. * chore(ci): add golangci-lint action * chore(lint): address errcheck lint failures * chore(lint): address misspell lint failures * chore(lint): address gocritic lint failures * chore(lint): address golint lint failures * chore(lint): address structcheck lint failures * chore(lint): address gosimple lint failures * chore(lint): address gofmt lint failures * chore(ci): port to official golangci-lint github action * Update golangci configuration for better coverage Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com> * fix: file is not goimports-ed Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com> * fix: golint and exported functions comments Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com> * chore(lint): address gosec G304 warning * chore(lint): address uparam warnings * chore(lint): address scopelint lint failures * fix: cyclomatic complexity Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com> * chore(lint): address prealloc warning, noting that we are warning for now * chore(lint): address govet and errorlint failures * chore: clean up defer logic when checking errors Co-authored-by: Khosrow Moossavi <khos2ow@gmail.com>
75 lines
1.9 KiB
Go
75 lines
1.9 KiB
Go
package chglog
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/fatih/color"
|
|
emoji "github.com/kyokomi/emoji/v2"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestLoggerLogSilent(t *testing.T) {
|
|
color.NoColor = false
|
|
assert := assert.New(t)
|
|
|
|
stdout := &bytes.Buffer{}
|
|
stderr := &bytes.Buffer{}
|
|
logger := NewLogger(stdout, stderr, true, false)
|
|
logger.Log(":+1:Hello, World! :)")
|
|
assert.Equal("", stdout.String())
|
|
}
|
|
|
|
func TestLoggerLog(t *testing.T) {
|
|
color.NoColor = false
|
|
assert := assert.New(t)
|
|
|
|
stdout := &bytes.Buffer{}
|
|
stderr := &bytes.Buffer{}
|
|
logger := NewLogger(stdout, stderr, false, false)
|
|
logger.Log(":+1:Hello, World! :)")
|
|
assert.Equal(emoji.Sprint(":+1:Hello, World! :)\n"), stdout.String())
|
|
}
|
|
|
|
func TestLoggerLogNoEmoji(t *testing.T) {
|
|
color.NoColor = false
|
|
assert := assert.New(t)
|
|
|
|
stdout := &bytes.Buffer{}
|
|
stderr := &bytes.Buffer{}
|
|
logger := NewLogger(stdout, stderr, false, true)
|
|
logger.Log(":+1:Hello, World! :)")
|
|
assert.Equal(fmt.Sprint("Hello, World! :)\n"), stdout.String()) //nolint:gosimple
|
|
}
|
|
|
|
func TestLoggerError(t *testing.T) {
|
|
color.NoColor = false
|
|
assert := assert.New(t)
|
|
|
|
prefix := color.New(color.FgWhite, color.BgRed, color.Bold).SprintFunc()
|
|
|
|
// Basic
|
|
stdout := &bytes.Buffer{}
|
|
stderr := &bytes.Buffer{}
|
|
logger := NewLogger(stdout, stderr, false, false)
|
|
logger.Error("This is error message!! :dog:")
|
|
assert.Equal("", stdout.String())
|
|
assert.Equal(emoji.Sprint(fmt.Sprintf("%s %s\n", prefix(" ERROR "), color.RedString("This is error message!! :dog:"))), stderr.String())
|
|
|
|
// Silent
|
|
stdout = &bytes.Buffer{}
|
|
stderr = &bytes.Buffer{}
|
|
logger = NewLogger(stdout, stderr, true, false)
|
|
logger.Error("Foo")
|
|
assert.Equal("", stdout.String())
|
|
assert.NotEqual("", stderr.String())
|
|
|
|
// NoEmoji
|
|
stdout = &bytes.Buffer{}
|
|
stderr = &bytes.Buffer{}
|
|
logger = NewLogger(stdout, stderr, true, true)
|
|
logger.Error("HOGE :hand:")
|
|
assert.Equal("", stdout.String())
|
|
assert.NotContains(stderr.String(), emoji.Sprint(":hand:"))
|
|
}
|