Skip to content

Commit

Permalink
chore: added github actions & test coverage (#2)
Browse files Browse the repository at this point in the history
* chore: added github actions

* chore: fix config

* chore: fix config for gh actions

* chore: fix config for gh actions

* chore: update lint command

* debt: fix test command

* chore: updated README
  • Loading branch information
clok authored Jul 17, 2020
1 parent 0f1d26a commit c742ab9
Show file tree
Hide file tree
Showing 7 changed files with 632 additions and 44 deletions.
22 changes: 11 additions & 11 deletions .chglog/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ options:
# - perf
# - refactor
commit_groups:
title_maps:
feat: Features
fix: Bug Fixes
bugfix: Bug Fixes
perf: Performance Improvements
refactor: Code Refactoring
chore: Chore
devops: DevOps
techdebt: Tech Debt
debt: Tech Debt
hotfix: Hot Fix
title_maps:
feat: Features
fix: Bug Fixes
bugfix: Bug Fixes
perf: Performance Improvements
refactor: Code Refactoring
chore: Chore
devops: DevOps
techdebt: Tech Debt
debt: Tech Debt
hotfix: Hot Fix
header:
pattern: "^((?:[^v][^\\d\\.])[\\w\\-]*)(?:\\((.*?)\\))?\\:?\\s?(.+)$"
pattern_maps:
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
on: [push, pull_request]
name: test and build
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: 1.14.x
- name: Checkout code
uses: actions/checkout@v1
- name: Install golangci-lint
run: |
go get github.com/golangci/golangci-lint/cmd/golangci-lint
- name: Run linters
run: |
export PATH=$PATH:$(go env GOPATH)/bin
golangci-lint -E bodyclose,misspell,gocyclo,dupl,gofmt,golint,unconvert,depguard,gocritic,interfacer -D structcheck run
coverage:
runs-on: ubuntu-latest
steps:
- name: Install Go
if: success()
uses: actions/setup-go@v1
with:
go-version: 1.14.x
- name: Checkout code
uses: actions/checkout@v1
- name: Calc coverage
run: |
export PATH=$PATH:$(go env GOPATH)/bin
go test -v -covermode=count -coverprofile=coverage.out -run ^Test_
- name: Convert coverage to lcov
uses: jandelgado/gcov2lcov-action@v1.0.0
with:
infile: coverage.out
outfile: coverage.lcov
- name: Coveralls
uses: coverallsapp/github-action@v1.0.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: coverage.lcov
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# kemba
[![Go Report Card](https://goreportcard.com/badge/clok/kemba)](https://goreportcard.com/report/clok/kemba)
[![Go Report Card](https://goreportcard.com/badge/clok/kemba)](https://goreportcard.com/report/clok/kemba) [![Coverage Status](https://coveralls.io/repos/github/clok/kemba/badge.svg?branch=chore/test-coverage)](https://coveralls.io/github/clok/kemba?branch=chore/test-coverage)

`debug` logging tool inspired by https://github.com/visionmedia/debug

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module kemba
go 1.14

require (
github.com/golangci/golangci-lint v1.28.3 // indirect
github.com/kr/pretty v0.2.0
github.com/stretchr/testify v1.6.1 // indirect
gopkg.in/gookit/color.v1 v1.1.6
Expand Down
546 changes: 546 additions & 0 deletions go.sum

Large diffs are not rendered by default.

26 changes: 9 additions & 17 deletions kemba.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"time"
)

type kLog struct {
type Kemba struct {
tag string
allowed string
enabled bool
Expand Down Expand Up @@ -103,11 +103,11 @@ var (
}
)

// New Returns a kLog logging instance
func New(tag string) *kLog {
// New Returns a Kemba logging instance
func New(tag string) *Kemba {
allowed := os.Getenv("DEBUG")

logger := kLog{tag: tag, allowed: allowed}
logger := Kemba{tag: tag, allowed: allowed}

if os.Getenv("DEBUG") != "" {
logger.enabled = determineEnabled(tag, allowed)
Expand Down Expand Up @@ -136,7 +136,7 @@ func New(tag string) *kLog {

// Printf is a convenience wrapper that will apply pretty.Formatter to the passed in variables.
// Calling Printf(f, x, y) is equivalent to fmt.Printf(f, Formatter(x), Formatter(y)).
func (k kLog) Printf(format string, v ...interface{}) {
func (k Kemba) Printf(format string, v ...interface{}) {
if k.enabled {
var buf bytes.Buffer
_, _ = pretty.Fprintf(&buf, format, v...)
Expand All @@ -150,7 +150,7 @@ func (k kLog) Printf(format string, v ...interface{}) {

// Println is a convenience wrapper that will apply pretty.Formatter to the passed in variables.
// Calling Println(x, y) is equivalent to fmt.Println(Formatter(x), Formatter(y)), but each operand is formatted with "%# v".
func (k kLog) Println(v ...interface{}) {
func (k Kemba) Println(v ...interface{}) {
if k.enabled {
for _, x := range v {
var buf bytes.Buffer
Expand All @@ -165,7 +165,7 @@ func (k kLog) Println(v ...interface{}) {
}

// Log is an alias to Println
func (k kLog) Log(v ...interface{}) {
func (k Kemba) Log(v ...interface{}) {
k.Println(v...)
}

Expand All @@ -189,17 +189,9 @@ func determineEnabled(tag string, allowed string) bool {
if !a {
a, _ = regexp.Match(reg, []byte(tag))
}
} else {
if !a {
a = l == tag
}
} else if !a {
a = l == tag
}
}
return a
}

// toggleColor with turn color on and off.
// TODO: enable functionality
func (k kLog) toggleColor() {
k.color = !k.color
}
35 changes: 20 additions & 15 deletions kemba_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package kemba

import (
"fmt"
"io/ioutil"
"os"
"strings"
Expand Down Expand Up @@ -129,7 +128,7 @@ func Example() {
// example:tag:1 bool(true)
}

func ExampleKLog_Printf() {
func ExampleKemba_Printf() {
_ = os.Setenv("DEBUG", "test:*")
k := New("test:kemba")
k.Printf("%s", "Hello")
Expand All @@ -154,7 +153,8 @@ func ExampleKLog_Printf() {
k1.Printf("%# v", m)

type myType struct {
a, b int
a int
b int
}
var x = []myType{{1, 2}, {3, 4}, {5, 6}}
k3.Printf("%# v", x)
Expand All @@ -164,13 +164,14 @@ func ExampleKLog_Printf() {
_ = os.Setenv("DEBUG", "")
}

func ExampleKLog_Printf_With_Expanded_Struct() {
func ExampleKemba_Printf_expanded() {
_ = os.Setenv("DEBUG", "test:*")
k := New("test:kemba")
k.Printf("%s", "Hello")

type myType struct {
a, b int
a int
b int
}
var x = []myType{{1, 2}, {3, 4}, {5, 6}}

Expand All @@ -187,12 +188,13 @@ func ExampleKLog_Printf_With_Expanded_Struct() {
// test:kemba }
}

func ExampleKLog_Printf_With_Compact_Struct() {
func ExampleKemba_Printf_compact() {
_ = os.Setenv("DEBUG", "test:*")
k := New("test:kemba")

type myType struct {
a, b int
a int
b int
}
var x = []myType{{1, 2}, {3, 4}, {5, 6}}

Expand Down Expand Up @@ -238,7 +240,7 @@ func Test_Printf(t *testing.T) {
out, _ := ioutil.ReadAll(r)
os.Stderr = rescueStderr

wantMsg := fmt.Sprint("test:kemba key: test value: 1337\n")
wantMsg := "test:kemba key: test value: 1337\n"
if string(out) != wantMsg {
t.Errorf("%#v, wanted %#v", string(out), wantMsg)
}
Expand Down Expand Up @@ -291,7 +293,8 @@ test:kemba string

k := New("test:kemba")
type myType struct {
a, b int
a int
b int
}
var x = []myType{{1, 2}, {3, 4}, {5, 6}}
k.Printf("%#v", x)
Expand Down Expand Up @@ -362,7 +365,7 @@ test:kemba }
if !strings.Contains(string(out), "test:kemba") {
t.Errorf("Expected string %#v to contain %#v", string(out), "test:kemba")
}
if os.Getenv("CI") != "" {
if os.Getenv("CI") == "" {
if !strings.Contains(string(out), "\x1b[") {
t.Errorf("Expected string %#v to contain %#v", string(out), "\x1b[")
}
Expand All @@ -372,13 +375,14 @@ test:kemba }
})
}

func ExampleKLog_Println() {
func ExampleKemba_Println() {
_ = os.Setenv("DEBUG", "test:*")
k := New("test:kemba")
k.Printf("%s", "Hello")

type myType struct {
a, b int
a int
b int
}
var x = []myType{{1, 2}, {3, 4}, {5, 6}}
k.Println(x)
Expand Down Expand Up @@ -506,7 +510,8 @@ test:kemba string

k := New("test:kemba")
type myType struct {
a, b int
a int
b int
}
var x = []myType{{1, 2}, {3, 4}, {5, 6}}
k.Println(x)
Expand Down Expand Up @@ -549,7 +554,7 @@ test:kemba }
if !strings.Contains(string(out), "test:kemba") {
t.Errorf("Expected string %#v to contain %#v", string(out), "test:kemba")
}
if os.Getenv("CI") != "" {
if os.Getenv("CI") == "" {
if !strings.Contains(string(out), "\x1b[") {
t.Errorf("Expected string %#v to contain %#v", string(out), "\x1b[")
}
Expand All @@ -560,7 +565,7 @@ test:kemba }

}

func ExampleKLog_Log() {
func ExampleKemba_Log() {
_ = os.Setenv("DEBUG", "test:*")
k := New("test:kemba")
k.Printf("%s", "Hello")
Expand Down

0 comments on commit c742ab9

Please # to comment.