Skip to content

Commit

Permalink
fix: fix go-libs tests with traces (#487)
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-nicolas authored Aug 17, 2023
1 parent f217c41 commit 2f58c7b
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 9 deletions.
10 changes: 5 additions & 5 deletions components/ledger/libs/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ require (
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.8.3
github.com/uptrace/bun v1.1.12
github.com/uptrace/bun/dialect/pgdialect v1.1.12
github.com/uptrace/bun/extra/bundebug v1.1.12
github.com/uptrace/bun v1.1.14
github.com/uptrace/bun/dialect/pgdialect v1.1.14
github.com/uptrace/bun/extra/bundebug v1.1.14
github.com/uptrace/opentelemetry-go-extra/otellogrus v0.1.21
github.com/xdg-go/scram v1.1.2
go.opentelemetry.io/contrib/instrumentation/host v0.42.0
Expand Down Expand Up @@ -70,7 +70,7 @@ require (
github.com/eapache/go-resiliency v1.3.0 // indirect
github.com/eapache/go-xerial-snappy v0.0.0-20230111030713-bf00bc1b83b6 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/fatih/color v1.14.1 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-chi/chi v4.1.2+incompatible // indirect
Expand Down Expand Up @@ -102,7 +102,7 @@ require (
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/minio/highwayhash v1.0.2 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae // indirect
Expand Down
11 changes: 11 additions & 0 deletions components/ledger/libs/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fatih/color v1.14.1 h1:qfhVLaG5s+nCROl1zJsZRxFeYrHLqWroPOQ8BWiNb4w=
github.com/fatih/color v1.14.1/go.mod h1:2oHN61fhTpgcxD3TSWCgKDiH1+x4OiDVVGH8WlgGZGg=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk=
github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
Expand Down Expand Up @@ -322,6 +324,8 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g=
github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY=
Expand Down Expand Up @@ -444,10 +448,16 @@ github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc h1:9lRDQMhESg+zvGYm
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc/go.mod h1:bciPuU6GHm1iF1pBvUfxfsH0Wmnc2VbpgvbI9ZWuIRs=
github.com/uptrace/bun v1.1.12 h1:sOjDVHxNTuM6dNGaba0wUuz7KvDE1BmNu9Gqs2gJSXQ=
github.com/uptrace/bun v1.1.12/go.mod h1:NPG6JGULBeQ9IU6yHp7YGELRa5Agmd7ATZdz4tGZ6z0=
github.com/uptrace/bun v1.1.14 h1:S5vvNnjEynJ0CvnrBOD7MIRW7q/WbtvFXrdfy0lddAM=
github.com/uptrace/bun v1.1.14/go.mod h1:RHk6DrIisO62dv10pUOJCz5MphXThuOTpVNYEYv7NI8=
github.com/uptrace/bun/dialect/pgdialect v1.1.12 h1:m/CM1UfOkoBTglGO5CUTKnIKKOApOYxkcP2qn0F9tJk=
github.com/uptrace/bun/dialect/pgdialect v1.1.12/go.mod h1:Ij6WIxQILxLlL2frUBxUBOZJtLElD2QQNDcu/PWDHTc=
github.com/uptrace/bun/dialect/pgdialect v1.1.14 h1:b7+V1KDJPQSFYgkG/6YLXCl2uvwEY3kf/GSM7hTHRDY=
github.com/uptrace/bun/dialect/pgdialect v1.1.14/go.mod h1:v6YiaXmnKQ2FlhRD2c0ZfKd+QXH09pYn4H8ojaavkKk=
github.com/uptrace/bun/extra/bundebug v1.1.12 h1:y8nrHvo7TUCR91kXngWuF7Bk0E1nCTsWzYL1CDEriTo=
github.com/uptrace/bun/extra/bundebug v1.1.12/go.mod h1:psjCrCMf5JaAyivW/A8MDBW5MwIy/jZFBCkIaBgabtM=
github.com/uptrace/bun/extra/bundebug v1.1.14 h1:9OCGfP9ZDlh41u6OLerWdhBtJAVGXHr0xtxO4xWi6t0=
github.com/uptrace/bun/extra/bundebug v1.1.14/go.mod h1:lto3guzS2v6mnQp1+akyE+ecBLOltevDDe324NXEYdw=
github.com/uptrace/opentelemetry-go-extra/otellogrus v0.1.21 h1:OXsouNDvuET5o1A4uvoCnAXuuNke8JlfZWceciyUlC8=
github.com/uptrace/opentelemetry-go-extra/otellogrus v0.1.21/go.mod h1:Xm3wlRGm5xzdAGPOvqydXPiGj0Da1q0OlUNm7Utoda4=
github.com/uptrace/opentelemetry-go-extra/otelutil v0.1.21 h1:HCqo51kNF8wxDMDhxcN5S6DlfZXigMtptRpkvjBCeVc=
Expand Down Expand Up @@ -707,6 +717,7 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
4 changes: 2 additions & 2 deletions components/ledger/libs/otlp/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

var (
onceInitOTLPFlags sync.Once
onceLoadResources sync.Once
OnceLoadResources sync.Once
)

const (
Expand All @@ -30,7 +30,7 @@ func InitOTLPFlags(flags *flag.FlagSet) {

func LoadResource(serviceName string, resourceAttributes []string) fx.Option {
options := make([]fx.Option, 0)
onceLoadResources.Do(func() {
OnceLoadResources.Do(func() {
options = append(options,
fx.Provide(func() (*resource.Resource, error) {
defaultResource := resource.Default()
Expand Down
5 changes: 5 additions & 0 deletions components/ledger/libs/otlp/otlptraces/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"errors"
"fmt"
"reflect"
"sync"
"testing"

"github.com/formancehq/stack/libs/go-libs/otlp"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -45,6 +47,9 @@ func TestOTLPTracesModule(t *testing.T) {
t.Run(testCase.name, func(t *testing.T) {
cmd := &cobra.Command{
PreRunE: func(cmd *cobra.Command, args []string) error {
// Since we are doing multiple tests with the same otlp
// package, we have to reset the once variables.
otlp.OnceLoadResources = sync.Once{}
return viper.BindPFlags(cmd.Flags())
},
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down
5 changes: 5 additions & 0 deletions components/ledger/libs/otlp/otlptraces/traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package otlptraces

import (
"context"
"sync"
"testing"

"github.com/formancehq/stack/libs/go-libs/otlp"
Expand Down Expand Up @@ -67,6 +68,10 @@ func TestTracesModule(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
// Since we are doing multiple tests with the same otlp
// package, we have to reset the once variables.
otlp.OnceLoadResources = sync.Once{}

options := []fx.Option{TracesModule(test.config)}
if !testing.Verbose() {
options = append(options, fx.NopLogger)
Expand Down
4 changes: 2 additions & 2 deletions libs/go-libs/otlp/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

var (
onceInitOTLPFlags sync.Once
onceLoadResources sync.Once
OnceLoadResources sync.Once
)

const (
Expand All @@ -30,7 +30,7 @@ func InitOTLPFlags(flags *flag.FlagSet) {

func LoadResource(serviceName string, resourceAttributes []string) fx.Option {
options := make([]fx.Option, 0)
onceLoadResources.Do(func() {
OnceLoadResources.Do(func() {
options = append(options,
fx.Provide(func() (*resource.Resource, error) {
defaultResource := resource.Default()
Expand Down
5 changes: 5 additions & 0 deletions libs/go-libs/otlp/otlptraces/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"errors"
"fmt"
"reflect"
"sync"
"testing"

"github.com/formancehq/stack/libs/go-libs/otlp"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -45,6 +47,9 @@ func TestOTLPTracesModule(t *testing.T) {
t.Run(testCase.name, func(t *testing.T) {
cmd := &cobra.Command{
PreRunE: func(cmd *cobra.Command, args []string) error {
// Since we are doing multiple tests with the same otlp
// package, we have to reset the once variables.
otlp.OnceLoadResources = sync.Once{}
return viper.BindPFlags(cmd.Flags())
},
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down
5 changes: 5 additions & 0 deletions libs/go-libs/otlp/otlptraces/traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package otlptraces

import (
"context"
"sync"
"testing"

"github.com/formancehq/stack/libs/go-libs/otlp"
Expand Down Expand Up @@ -67,6 +68,10 @@ func TestTracesModule(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
// Since we are doing multiple tests with the same otlp
// package, we have to reset the once variables.
otlp.OnceLoadResources = sync.Once{}

options := []fx.Option{TracesModule(test.config)}
if !testing.Verbose() {
options = append(options, fx.NopLogger)
Expand Down

1 comment on commit 2f58c7b

@vercel
Copy link

@vercel vercel bot commented on 2f58c7b Aug 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.