Skip to content

Commit

Permalink
hotfix ga settings
Browse files Browse the repository at this point in the history
  • Loading branch information
schoren committed May 10, 2022
1 parent a5d06a4 commit 0376568
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ services:
container_name: tracetest
image: kubeshop/tracetest
build: .
environment:
- VERSION=1.0
volumes:
- type: bind
source: ./server/config.yaml
Expand Down
9 changes: 6 additions & 3 deletions server/analytics/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func Init(cfg config.GoogleAnalytics, appName, appVersion string) error {
}

defaultClient = ga{
enabled: cfg.Enabled,
enabled: true,
measurementID: cfg.MeasurementID,
secretKey: cfg.SecretKey,
appVersion: appVersion,
Expand All @@ -52,12 +52,16 @@ func Init(cfg config.GoogleAnalytics, appName, appVersion string) error {
}

func CreateAndSendEvent(name, category string) error {
if defaultClient.ready() {
if !defaultClient.ready() {
return fmt.Errorf("uninitalized client. Call analytics.Init")
}
return defaultClient.CreateAndSendEvent(name, category)
}

func Ready() bool {
return defaultClient.ready()
}

type ga struct {
enabled bool
appVersion string
Expand Down Expand Up @@ -115,7 +119,6 @@ func (ga ga) sendEvent(e event) error {
},
}

fmt.Printf("ga %+v\n", payload)
err := ga.sendValidationRequest(payload)
if err != nil {
fmt.Println("err validation", err)
Expand Down
46 changes: 46 additions & 0 deletions server/analytics/analytics_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package analytics_test

import (
"testing"

"github.com/kubeshop/tracetest/analytics"
"github.com/kubeshop/tracetest/config"
"github.com/stretchr/testify/assert"
)

func TestReadyness(t *testing.T) {
analytics.Init(config.GoogleAnalytics{Enabled: false}, "test", "1.0")
assert.True(t, analytics.Ready())

analytics.Init(config.GoogleAnalytics{Enabled: true}, "test", "1.0")
assert.False(t, analytics.Ready())

analytics.Init(config.GoogleAnalytics{
Enabled: true,
MeasurementID: "1",
SecretKey: "2",
}, "test", "1.0")
assert.True(t, analytics.Ready())

analytics.Init(config.GoogleAnalytics{
Enabled: true,
MeasurementID: "1",
SecretKey: "2",
}, "test", "1.0")
assert.True(t, analytics.Ready())

analytics.Init(config.GoogleAnalytics{
Enabled: true,
MeasurementID: "1",
SecretKey: "2",
}, "", "1.0")
assert.False(t, analytics.Ready())

analytics.Init(config.GoogleAnalytics{
Enabled: true,
MeasurementID: "1",
SecretKey: "2",
}, "test", "")
assert.False(t, analytics.Ready())

}

0 comments on commit 0376568

Please sign in to comment.