mirror of
https://github.com/git-chglog/git-chglog.git
synced 2026-01-23 02:15:12 +00:00
feat: add Jira integration (#52)
This commit is contained in:
parent
8713d96856
commit
a1c84d7a0d
22 changed files with 742 additions and 331 deletions
75
logger_test.go
Normal file
75
logger_test.go
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
package chglog
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/stretchr/testify/assert"
|
||||
emoji "github.com/kyokomi/emoji/v2"
|
||||
)
|
||||
|
||||
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())
|
||||
}
|
||||
|
||||
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:"))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue