diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index e7f9c2b9a..cd93843db 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -60,7 +60,6 @@ jobs: echo "GOROOT=$HOME/gotip" >> $GITHUB_ENV echo "$HOME/gotip/bin" >> $GITHUB_PATH - - name: Check out code into the Go module directory uses: percona-platform/checkout@v2 diff --git a/main.go b/main.go index 05ac078e8..401877bd7 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,7 @@ package main import ( "fmt" + "log" "strings" "github.com/alecthomas/kong" @@ -72,6 +73,15 @@ func main() { return } + e, err := buildExporter(opts) + if err != nil { + log.Fatal(err) + } + + e.Run() +} + +func buildExporter(opts GlobalFlags) (*exporter.Exporter, error) { log := logrus.New() levels := map[string]logrus.Level{ @@ -95,7 +105,7 @@ func main() { exporterOpts := &exporter.Opts{ CollStatsCollections: strings.Split(opts.CollStatsCollections, ","), CompatibleMode: opts.CompatibleMode, - IndexStatsCollections: strings.Split(opts.CollStatsCollections, ","), + IndexStatsCollections: strings.Split(opts.IndexStatsCollections, ","), Logger: log, Path: opts.WebTelemetryPath, URI: opts.URI, @@ -107,8 +117,8 @@ func main() { e, err := exporter.New(exporterOpts) if err != nil { - log.Fatal(err) + return nil, err } - e.Run() + return e, nil } diff --git a/main_test.go b/main_test.go new file mode 100644 index 000000000..cfcdf35ee --- /dev/null +++ b/main_test.go @@ -0,0 +1,27 @@ +package main + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestBuildExporter(t *testing.T) { + opts := GlobalFlags{ + CollStatsCollections: "c1,c2,c3", + IndexStatsCollections: "i1,i2,i3", + URI: "mongodb://usr:pwd@127.0.0.1/", + GlobalConnPool: false, // to avoid testing the connection + WebListenAddress: "localhost:12345", + WebTelemetryPath: "/mymetrics", + LogLevel: "debug", + + DisableDiagnosticData: true, + DisableReplicasetStatus: true, + + CompatibleMode: true, + } + + _, err := buildExporter(opts) + assert.NoError(t, err) +}