Skip to content

Commit

Permalink
Write tests for the internal/log package
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronsky committed Apr 22, 2021
1 parent 4363ab8 commit 89a1181
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
10 changes: 6 additions & 4 deletions internal/clicommand/clicommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ along with Cider. If not, see <http://www.gnu.org/licenses/>.
package clicommand

import (
"os"

"github.com/cidertool/cider/internal/log"
"github.com/fatih/color"
)

func newLogger(debugFlagValue *bool) *log.Log {
logger := log.New()

// Comment this out as it's causing issues during parallel testing
// if os.Getenv("CI") != "" {
// logger.SetColorMode(false)
// }
if os.Getenv("CI") != "" && color.NoColor {
logger.SetColorMode(false)
}

if debugFlagValue != nil {
logger.SetDebug(*debugFlagValue)
Expand Down
4 changes: 2 additions & 2 deletions internal/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ func (l *Log) SetDebug(v bool) {
defer l.mu.Unlock()

if v {
l.Logger.Level = log.DebugLevel
l.Level = log.DebugLevel
} else {
l.Logger.Level = log.InfoLevel
l.Level = log.InfoLevel
}
}

Expand Down
26 changes: 25 additions & 1 deletion internal/log/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,28 @@ along with Cider. If not, see <http://www.gnu.org/licenses/>.

package log

// this package has no testable statements
import (
"testing"

alog "github.com/apex/log"
"github.com/fatih/color"
"github.com/stretchr/testify/assert"
)

func TestLog(t *testing.T) {
t.Parallel()

log := New()

log.SetPadding(4)

log.SetColorMode(false)
assert.False(t, color.NoColor)
log.SetColorMode(true)
assert.True(t, color.NoColor)

log.SetDebug(true)
assert.Equal(t, log.Level, alog.DebugLevel)
log.SetDebug(false)
assert.Equal(t, log.Level, alog.InfoLevel)
}

0 comments on commit 89a1181

Please sign in to comment.