Skip to content

Commit

Permalink
Add support for tracker namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
francoiscampbell committed Jul 14, 2022
1 parent 1cb87c8 commit 21568e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
11 changes: 9 additions & 2 deletions snowplowtrk.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ func main() {
Usage: "Application Id (Optional)",
Value: appName,
},
cli.StringFlag{
Name: "namespace, ns",
Usage: "Tracker Namespace (Optional)",
Value: appName,
},
cli.StringFlag{
Name: "method, m",
Usage: "Method[POST|GET] (Optional)",
Expand Down Expand Up @@ -103,6 +108,7 @@ func main() {
app.Action = func(c *cli.Context) error {
collector := c.String("collector")
appid := c.String("appid")
namespace := c.String("namespace")
method := c.String("method")
protocol := c.String("protocol")
sdjson := c.String("sdjson")
Expand Down Expand Up @@ -132,7 +138,7 @@ func main() {
trackerChan := make(chan int, 1)

// Send the event
tracker := initTracker(collector, appid, method, protocol, ipAddress, trackerChan, nil)
tracker := initTracker(collector, appid, namespace, method, protocol, ipAddress, trackerChan, nil)
statusCode := trackSelfDescribingEvent(tracker, trackerChan, sdj, contextArr)

// Parse return code
Expand Down Expand Up @@ -203,7 +209,7 @@ func getContexts(contexts string) ([]gt.SelfDescribingJson, error) {

// initTracker creates a new Tracker ready for use
// by the application.
func initTracker(collector string, appid string, method string, protocol string, ipAddress string, trackerChan chan int, httpClient *http.Client) *gt.Tracker {
func initTracker(collector string, appid string, namespace string, method string, protocol string, ipAddress string, trackerChan chan int, httpClient *http.Client) *gt.Tracker {

// Create callback function
callback := func(s []gt.CallbackResult, f []gt.CallbackResult) {
Expand Down Expand Up @@ -234,6 +240,7 @@ func initTracker(collector string, appid string, method string, protocol string,
gt.RequireEmitter(emitter),
gt.OptionSubject(subject),
gt.OptionAppId(appid),
gt.OptionNamespace(namespace),
)

return tracker
Expand Down
7 changes: 4 additions & 3 deletions snowplowtrk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ func TestInitTracker(t *testing.T) {
assert := assert.New(t)
trackerChan := make(chan int, 1)

tracker := initTracker("com.acme", "myapp", "POST", "https", "", trackerChan, nil)
tracker := initTracker("com.acme", "myapp", "mynamespace", "POST", "https", "", trackerChan, nil)
assert.NotNil(tracker)
assert.NotNil(tracker.Emitter)
assert.NotNil(tracker.Subject)
assert.Equal("myapp", tracker.AppId)
assert.Equal("mynamespace", tracker.Namespace)
}

func TestTrackSelfDescribingEventGood(t *testing.T) {
Expand All @@ -124,7 +125,7 @@ func TestTrackSelfDescribingEventGood(t *testing.T) {

// Setup Tracker
trackerChan := make(chan int, 1)
tracker := initTracker("com.acme", "myapp", "GET", "http", "", trackerChan, httpClient)
tracker := initTracker("com.acme", "myapp", "mynamespace", "GET", "http", "", trackerChan, httpClient)
assert.NotNil(tracker)

// Make SDJ
Expand Down Expand Up @@ -163,7 +164,7 @@ func TestTrackSelfDescribingEventBad(t *testing.T) {

// Setup Tracker
trackerChan := make(chan int, 1)
tracker := initTracker("com.acme", "myapp", "POST", "http", "", trackerChan, httpClient)
tracker := initTracker("com.acme", "myapp", "mynamespace", "POST", "http", "", trackerChan, httpClient)
assert.NotNil(tracker)

// Make SDJ
Expand Down

0 comments on commit 21568e6

Please sign in to comment.