From 733e4878e3fe4dce22de701b22cce895cb971f8d Mon Sep 17 00:00:00 2001 From: aalur Date: Wed, 15 Nov 2023 17:29:52 -0800 Subject: [PATCH 1/5] Test for log bug --- main_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/main_test.go b/main_test.go index cdda1d0..0229256 100644 --- a/main_test.go +++ b/main_test.go @@ -5,8 +5,19 @@ import ( "os" "reflect" "testing" + + "fortio.org/log" ) +func TestLoggerNotWorking(t *testing.T) { + req := SlackPostMessageRequest{} + + err := validate(req) + + log.S(log.Error, "Testing logging", log.Any("err", err)) + log.S(log.Error, "Testing logging", log.Any("err", err.Error())) +} + func TestGetSlackTokens(t *testing.T) { tests := []struct { name string From a28c30d909abd73a5cc0a5d6aa543a3705878230 Mon Sep 17 00:00:00 2001 From: Laurent Demailly Date: Wed, 15 Nov 2023 19:38:37 -0800 Subject: [PATCH 2/5] update deps, including fixed version of log pre release for error logging --- go.mod | 31 ++++++++++++------------ go.sum | 66 ++++++++++++++++++++++++---------------------------- main_test.go | 5 ++-- server.go | 2 +- 4 files changed, 48 insertions(+), 56 deletions(-) diff --git a/go.mod b/go.mod index fd4a9e2..cbebfe5 100644 --- a/go.mod +++ b/go.mod @@ -4,30 +4,29 @@ go 1.20 require ( fortio.org/assert v1.2.0 - fortio.org/fortio v1.60.3 - fortio.org/log v1.12.0-pre1 - fortio.org/scli v1.12.0 + fortio.org/fortio v1.61.0 + fortio.org/log v1.12.0-pre2 + fortio.org/scli v1.12.1 github.com/prometheus/client_golang v1.17.0 - golang.org/x/time v0.3.0 + golang.org/x/time v0.4.0 ) require ( fortio.org/cli v1.4.2 // indirect - fortio.org/dflag v1.6.0 // indirect + fortio.org/dflag v1.7.0 // indirect fortio.org/sets v1.0.3 // indirect fortio.org/version v1.0.3 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect - github.com/fsnotify/fsnotify v1.6.0 // indirect - github.com/golang/protobuf v1.5.3 // indirect - github.com/google/uuid v1.3.1 // indirect - github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect - github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect - github.com/prometheus/common v0.44.0 // indirect - github.com/prometheus/procfs v0.11.1 // indirect - golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect - golang.org/x/net v0.17.0 // indirect - golang.org/x/sys v0.13.0 // indirect - golang.org/x/text v0.13.0 // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect + github.com/google/uuid v1.4.0 // indirect + github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect + github.com/prometheus/client_model v0.5.0 // indirect + github.com/prometheus/common v0.45.0 // indirect + github.com/prometheus/procfs v0.12.0 // indirect + golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect + golang.org/x/net v0.18.0 // indirect + golang.org/x/sys v0.14.0 // indirect + golang.org/x/text v0.14.0 // indirect google.golang.org/protobuf v1.31.0 // indirect ) diff --git a/go.sum b/go.sum index d885b3f..6a94ef4 100644 --- a/go.sum +++ b/go.sum @@ -2,14 +2,14 @@ fortio.org/assert v1.2.0 h1:XscfvR8yp4xW7OMCvNbCsieRFDxlwdEcb69+JZRp6LA= fortio.org/assert v1.2.0/go.mod h1:039mG+/iYDPO8Ibx8TrNuJCm2T2SuhwRI3uL9nHTTls= fortio.org/cli v1.4.2 h1:pCYVPk5FpQuJtD31f9CG8sdgoTOWdv9Gls8As/MLJhU= fortio.org/cli v1.4.2/go.mod h1:VGqFDEKpA6u3NbTM3aSz2lZfAYKnGaszl1pLxbBhxsY= -fortio.org/dflag v1.6.0 h1:acOc3KAu1kgp3Ov1nT2GbmcuNhPF1oMZqhT9nj3Oz1U= -fortio.org/dflag v1.6.0/go.mod h1:MeDNYnBh30L6OdMGgAL6ltDX2xdQjOiexCZYPYXH8uM= -fortio.org/fortio v1.60.3 h1:adR0uf/69M5xxKaMLAautVf9FIVkEpMwuEWyMaaSnI0= -fortio.org/fortio v1.60.3/go.mod h1:AiuXKYWtbDyXvfEQgkYhLsUbwSZF78lEd+rGYXJaziA= -fortio.org/log v1.12.0-pre1 h1:uhk9Xa8KxijA4xvNKYDPJ4AT6JoA1OsJPLO4x0+OPr8= -fortio.org/log v1.12.0-pre1/go.mod h1:u/8/2lyczXq52aT5Nw6reD+3cR6m/EbS2jBiIYhgiTU= -fortio.org/scli v1.12.0 h1:ABomNd0/RLgdGdf5lwgfwGhTuLwW3Of7bbTTgbN9r+g= -fortio.org/scli v1.12.0/go.mod h1:kLbbvX0QdnUOpQnW+7OsmY1d/qf5VMMkOiR+8GhqJII= +fortio.org/dflag v1.7.0 h1:4Vpo5hMly0rx9VMuyBaDGFK1Mx2S3qjxx1iAIA3KBgU= +fortio.org/dflag v1.7.0/go.mod h1:FUxv/s3DXhCpy7GsuZa4FJWLR92gsYvG3ylkia8MbBM= +fortio.org/fortio v1.61.0 h1:XISKJ36/eAYNQlVdNwnrZrQManOCIvGMqeJTW4RGi/o= +fortio.org/fortio v1.61.0/go.mod h1:s/qRsTjAC0iTknjMby54fbdkuriPx3A8OEJynC6b4VI= +fortio.org/log v1.12.0-pre2 h1:FIZk1nKvL6BuhlaKomZRMeWV/7NWDC+Xkd1YjoASoEk= +fortio.org/log v1.12.0-pre2/go.mod h1:u/8/2lyczXq52aT5Nw6reD+3cR6m/EbS2jBiIYhgiTU= +fortio.org/scli v1.12.1 h1:F+E6dPOCskBXpYNDJIU12tzY4Y8r1qTHa5Ge/CTLZtA= +fortio.org/scli v1.12.1/go.mod h1:CkLJR1sT9rZGsvVC9eouE1K0Ee4+p0lChiwO6Vw04lo= fortio.org/sets v1.0.3 h1:HzewdGjH69YmyW06yzplL35lGr+X4OcqQt0qS6jbaO4= fortio.org/sets v1.0.3/go.mod h1:QZVj0r6KP/ZD9ebySW9SgxVNy/NjghUfyHW9NN+WU+4= fortio.org/version v1.0.3 h1:5gJ3plj6isAOMq52cI5ifo4cC+QHmJF76Wevc5Cp4x0= @@ -19,40 +19,34 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= -github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= -github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= -github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= +github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= +github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg= +github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k= github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q= github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY= -github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 h1:v7DLqVdK4VrYkVD5diGdl4sxJurKJEMnODWRJlxV9oM= -github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU= -github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdOOfY= -github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY= -github.com/prometheus/procfs v0.11.1 h1:xRC8Iq1yyca5ypa9n1EZnWZkt7dwcoRPQwX/5gwaUuI= -github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/y0/p/ScXhY= -golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= -golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= -golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= -golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= +github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= +github.com/prometheus/common v0.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lneoxM= +github.com/prometheus/common v0.45.0/go.mod h1:YJmSTw9BoKxJplESWWxlbyttQR4uaEcGyv9MZjVOJsY= +github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= +github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= +golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa h1:FRnLl4eNAQl8hwxVVC17teOw8kdjVDVAiFMtgUdTSRQ= +golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE= +golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= +golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= +golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= +golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/time v0.4.0 h1:Z81tqI5ddIoXDPvVQ7/7CC9TnLM7ubaFG2qXYd5BbYY= +golang.org/x/time v0.4.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= diff --git a/main_test.go b/main_test.go index 0229256..7637758 100644 --- a/main_test.go +++ b/main_test.go @@ -9,13 +9,12 @@ import ( "fortio.org/log" ) -func TestLoggerNotWorking(t *testing.T) { +func TestLoggerNotWorking(_ *testing.T) { req := SlackPostMessageRequest{} err := validate(req) - log.S(log.Error, "Testing logging", log.Any("err", err)) - log.S(log.Error, "Testing logging", log.Any("err", err.Error())) + log.S(log.Error, "Testing logging - err", log.Any("err", err)) } func TestGetSlackTokens(t *testing.T) { diff --git a/server.go b/server.go index ddc2bcb..cb2761c 100644 --- a/server.go +++ b/server.go @@ -134,7 +134,7 @@ func validate(request SlackPostMessageRequest) error { } if len(errorMessages) > 0 { - return fmt.Errorf(strings.Join(errorMessages, " and ")) + return fmt.Errorf("%s", strings.Join(errorMessages, " and ")) } return nil From faa899e483aaf75bc1e44c8dfadac35aa819cd30 Mon Sep 17 00:00:00 2001 From: Laurent Demailly Date: Wed, 15 Nov 2023 19:45:53 -0800 Subject: [PATCH 3/5] make the test actually test something --- main_test.go | 13 +++++++++++-- server.go | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/main_test.go b/main_test.go index 7637758..0a87fc9 100644 --- a/main_test.go +++ b/main_test.go @@ -9,12 +9,21 @@ import ( "fortio.org/log" ) -func TestLoggerNotWorking(_ *testing.T) { +func TestLoggerNotWorking(t *testing.T) { req := SlackPostMessageRequest{} err := validate(req) - + if err == nil { + t.Errorf("Expected error on empty request validation, got nil") + } + // for running go test -v and seeing the log: log.S(log.Error, "Testing logging - err", log.Any("err", err)) + kv := log.Any("err", err) + kvStr := kv.StringValue() + expected := `"Channel is not set and Neither attachments, blocks, nor text is set"` + if kvStr != expected { + t.Errorf("Expected %s, got %s", expected, kvStr) + } } func TestGetSlackTokens(t *testing.T) { diff --git a/server.go b/server.go index cb2761c..ddc2bcb 100644 --- a/server.go +++ b/server.go @@ -134,7 +134,7 @@ func validate(request SlackPostMessageRequest) error { } if len(errorMessages) > 0 { - return fmt.Errorf("%s", strings.Join(errorMessages, " and ")) + return fmt.Errorf(strings.Join(errorMessages, " and ")) } return nil From e29148a70da38f37554e0def49a3d8c5b0c13f26 Mon Sep 17 00:00:00 2001 From: Laurent Demailly Date: Wed, 15 Nov 2023 19:47:06 -0800 Subject: [PATCH 4/5] rename test --- main_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main_test.go b/main_test.go index 0a87fc9..4dcebb2 100644 --- a/main_test.go +++ b/main_test.go @@ -9,7 +9,7 @@ import ( "fortio.org/log" ) -func TestLoggerNotWorking(t *testing.T) { +func TestValidateErrorsAndLogger(t *testing.T) { req := SlackPostMessageRequest{} err := validate(req) From a62e69c4bdf83c10be9d233adce5d0380c54b625 Mon Sep 17 00:00:00 2001 From: Laurent Demailly Date: Wed, 15 Nov 2023 20:39:51 -0800 Subject: [PATCH 5/5] use better version --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index cbebfe5..b37d5d3 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.20 require ( fortio.org/assert v1.2.0 fortio.org/fortio v1.61.0 - fortio.org/log v1.12.0-pre2 + fortio.org/log v1.12.0-pre3 fortio.org/scli v1.12.1 github.com/prometheus/client_golang v1.17.0 golang.org/x/time v0.4.0 diff --git a/go.sum b/go.sum index 6a94ef4..7e99f93 100644 --- a/go.sum +++ b/go.sum @@ -6,8 +6,8 @@ fortio.org/dflag v1.7.0 h1:4Vpo5hMly0rx9VMuyBaDGFK1Mx2S3qjxx1iAIA3KBgU= fortio.org/dflag v1.7.0/go.mod h1:FUxv/s3DXhCpy7GsuZa4FJWLR92gsYvG3ylkia8MbBM= fortio.org/fortio v1.61.0 h1:XISKJ36/eAYNQlVdNwnrZrQManOCIvGMqeJTW4RGi/o= fortio.org/fortio v1.61.0/go.mod h1:s/qRsTjAC0iTknjMby54fbdkuriPx3A8OEJynC6b4VI= -fortio.org/log v1.12.0-pre2 h1:FIZk1nKvL6BuhlaKomZRMeWV/7NWDC+Xkd1YjoASoEk= -fortio.org/log v1.12.0-pre2/go.mod h1:u/8/2lyczXq52aT5Nw6reD+3cR6m/EbS2jBiIYhgiTU= +fortio.org/log v1.12.0-pre3 h1:pDStix0DwdKAPibiot2OeY7U8huT/hbzcxWLevMlKUY= +fortio.org/log v1.12.0-pre3/go.mod h1:u/8/2lyczXq52aT5Nw6reD+3cR6m/EbS2jBiIYhgiTU= fortio.org/scli v1.12.1 h1:F+E6dPOCskBXpYNDJIU12tzY4Y8r1qTHa5Ge/CTLZtA= fortio.org/scli v1.12.1/go.mod h1:CkLJR1sT9rZGsvVC9eouE1K0Ee4+p0lChiwO6Vw04lo= fortio.org/sets v1.0.3 h1:HzewdGjH69YmyW06yzplL35lGr+X4OcqQt0qS6jbaO4=