analytics_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package analytics
  2. import "testing"
  3. func TestAnalytics(t *testing.T) {
  4. testingProps := func() map[string]interface{} {
  5. return map[string]interface{}{
  6. "string": 42,
  7. "uint": uint(23),
  8. "int": 42,
  9. "float": 42.2,
  10. "slice": []interface{}{"hello", 42},
  11. "map": map[string]interface{}{"foo": "bar"},
  12. "struct": struct{ Foo string }{Foo: "bar"},
  13. }
  14. }
  15. providers := []struct {
  16. name string
  17. backend Backend
  18. }{
  19. {
  20. name: "google analytics",
  21. backend: NewGoogleAnalytics(),
  22. },
  23. }
  24. for _, p := range providers {
  25. t.Run(p.name, func(t *testing.T) {
  26. Add(p.backend)
  27. defer func() {
  28. backends = nil
  29. }()
  30. t.Run("identify", func(t *testing.T) {
  31. Identify("Maxoo", nil)
  32. })
  33. t.Run("identify with traits", func(t *testing.T) {
  34. Identify("Maxoo", testingProps())
  35. })
  36. t.Run("event", func(t *testing.T) {
  37. Track("test", nil)
  38. })
  39. t.Run("event with properties", func(t *testing.T) {
  40. Track("test", testingProps())
  41. })
  42. t.Run("page", func(t *testing.T) {
  43. Page("Test", nil)
  44. })
  45. t.Run("page with properties", func(t *testing.T) {
  46. Page("Test", testingProps())
  47. })
  48. })
  49. }
  50. }