Skip to content

Commit

Permalink
chore: upgrade to go 1.22.3
Browse files Browse the repository at this point in the history
make test failures more readable

partly reverting stackskip_test.go to a state that shouldn't need updating on every go upgrade

related to jenkins-x/jx#8670
  • Loading branch information
msvticket committed Jun 4, 2024
1 parent 1e97e0a commit 57aae9b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 43 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ tidy-deps: ## Cleans up dependencies
make-reports-dir:
mkdir -p $(REPORTS_DIR)

.PHONY: test
test: ## Run tests with the "unit" build tag
KUBECONFIG=/cluster/connections/not/allowed CGO_ENABLED=$(CGO_ENABLED) $(GOTEST) --tags=unit -failfast -short ./... $(TEST_BUILDFLAGS)

Expand Down
12 changes: 8 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
module github.com/jenkins-x/logrus-stackdriver-formatter

go 1.19
go 1.22.3

require (
github.com/TV4/logrus-stackdriver-formatter v0.1.0
github.com/go-stack/stack v1.8.1
github.com/kr/pretty v0.3.0
github.com/sirupsen/logrus v1.9.0
github.com/stretchr/testify v1.7.0
)

require (
github.com/kr/text v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.6.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/TV4/logrus-stackdriver-formatter v0.1.0 h1:nFea8RiX7ecTnWPM+9FIqwZYJdcGo58CHMGIVdYzMXg=
github.com/TV4/logrus-stackdriver-formatter v0.1.0/go.mod h1:wwS7hOiBvP6SBD0UXCa767+VhHkaXrfX0MzUojYcN0Q=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand All @@ -23,6 +25,7 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
Expand Down
21 changes: 9 additions & 12 deletions pkg/stackdriver/formatter_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build unit
// +build unit

package stackdriver
Expand All @@ -6,12 +7,10 @@ import (
"bytes"
"encoding/json"
"errors"
"reflect"
"testing"

"github.com/kr/pretty"

"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)

func TestFormatter(t *testing.T) {
Expand All @@ -32,9 +31,7 @@ func TestFormatter(t *testing.T) {
var got map[string]interface{}
json.Unmarshal(out.Bytes(), &got)

if !reflect.DeepEqual(got, tt.out) {
t.Errorf("unexpected output = %# v; want = %# v", pretty.Formatter(got), pretty.Formatter(tt.out))
}
assert.Equal(t, tt.out, got)
}
}

Expand Down Expand Up @@ -73,8 +70,8 @@ var formatterTests = []struct {
},
"reportLocation": map[string]interface{}{
"filePath": "github.com/jenkins-x/logrus-stackdriver-formatter/pkg/stackdriver/formatter_test.go",
"lineNumber": 61.0,
"functionName": "glob..func2",
"lineNumber": 58.0,
"functionName": "init.func2",
},
},
},
Expand All @@ -99,8 +96,8 @@ var formatterTests = []struct {
},
"reportLocation": map[string]interface{}{
"filePath": "github.com/jenkins-x/logrus-stackdriver-formatter/pkg/stackdriver/formatter_test.go",
"lineNumber": 87.0,
"functionName": "glob..func3",
"lineNumber": 84.0,
"functionName": "init.func3",
},
},
},
Expand Down Expand Up @@ -132,8 +129,8 @@ var formatterTests = []struct {
},
"reportLocation": map[string]interface{}{
"filePath": "github.com/jenkins-x/logrus-stackdriver-formatter/pkg/stackdriver/formatter_test.go",
"lineNumber": 117.0,
"functionName": "glob..func4",
"lineNumber": 114.0,
"functionName": "init.func4",
},
},
},
Expand Down
39 changes: 12 additions & 27 deletions pkg/stackdriver/stackskip_test.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
//go:build unit
// +build unit

package stackdriver

import (
"bytes"
"encoding/json"
"reflect"
"testing"

"github.com/kr/pretty"
"github.com/TV4/logrus-stackdriver-formatter/test"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)

type logWrapper struct {
Logger *logrus.Logger
}

func (l *logWrapper) error(msg string) {
l.Logger.Error(msg)
}

func TestStackSkip(t *testing.T) {
var out bytes.Buffer

Expand All @@ -29,37 +18,33 @@ func TestStackSkip(t *testing.T) {
logger.Formatter = NewFormatter(
WithService("test"),
WithVersion("0.1"),
WithStackSkip("github.com/jenkins-x/logrus-stackdriver-formatter/pkg/stackdriver"),
WithStackSkip("github.com/TV4/logrus-stackdriver-formatter/test"),
)

mylog := logWrapper{
mylog := test.LogWrapper{
Logger: logger,
}

mylog.error("my log entry")
mylog.Error("my log entry")

var got map[string]interface{}
json.Unmarshal(out.Bytes(), &got)
got["timestamp"] = "2020-01-01T00:00:00.000000Z"
_ = json.Unmarshal(out.Bytes(), &got)

want := map[string]interface{}{
"severity": "ERROR",
"message": "my log entry",
"timestamp": "2020-01-01T00:00:00.000000Z",
"severity": "ERROR",
"message": "my log entry",
"serviceContext": map[string]interface{}{
"service": "test",
"version": "0.1",
},
"context": map[string]interface{}{
"reportLocation": map[string]interface{}{
"filePath": "testing/testing.go",
"lineNumber": float64(1446),
"functionName": "tRunner",
"filePath": "github.com/jenkins-x/logrus-stackdriver-formatter/pkg/stackdriver/stackskip_test.go",
"lineNumber": 28.0,
"functionName": "TestStackSkip",
},
},
}

if !reflect.DeepEqual(got, want) {
t.Errorf("unexpected output = %# v; want = %# v", pretty.Formatter(got), pretty.Formatter(want))
}
assert.Equal(t, want, got)
}

0 comments on commit 57aae9b

Please sign in to comment.