GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — go-lytics/segment_test.go at master · lytics/go-lytics

Expand file tree

/

segment_test.go

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
194 lines (153 loc) · 4.78 KB
/

segment_test.go

Copy path

File metadata and controls

194 lines (153 loc) · 4.78 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package lytics
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/jarcoal/httpmock"
"github.com/lytics/go-lytics/mock"
)
func TestGetSegments(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
mock.RegisterSegmentMocks()
// user segment
client := NewLytics(mock.MockApiKey, nil)
segs, err := client.GetSegments("user")
assert.Equal(t, err, nil)
assert.True(t, len(segs) > 1)
assert.Equal(t, segs[0].Table, "user")
// content segment
segs, err = client.GetSegments("content")
assert.Equal(t, err, nil)
assert.True(t, len(segs) > 1)
assert.Equal(t, segs[0].Table, "content")
}
func TestGetSegment(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
mock.RegisterSegmentMocks()
client := NewLytics(mock.MockApiKey, nil)
seg, err := client.GetSegment(mock.MockSegmentID1)
assert.Equal(t, err, nil)
assert.True(t, seg.Id == mock.MockSegmentID1)
}
func TestGetSegmentSize(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
mock.RegisterSegmentMocks()
client := NewLytics(mock.MockApiKey, nil)
seg, err := client.GetSegmentSize(mock.MockSegmentID1)
assert.Equal(t, err, nil)
assert.True(t, seg.Id == mock.MockSegmentID1)
}
func TestGetSegmentSizes(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
mock.RegisterSegmentMocks()
var segments []string
client := NewLytics(mock.MockApiKey, nil)
segments = []string{
mock.MockSegmentID1,
}
seg, err := client.GetSegmentSizes(segments)
assert.Equal(t, err, nil)
assert.True(t, seg[0].Id == segments[0])
segments = []string{
mock.MockSegmentID1,
mock.MockSegmentID2,
}
// params
seg, err = client.GetSegmentSizes(segments)
assert.Equal(t, err, nil)
assert.True(t, len(seg) == 2)
}
func TestGetSegmentAttribution(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
mock.RegisterSegmentMocks()
segments := []string{
mock.MockSegmentID1,
mock.MockSegmentID2,
}
client := NewLytics(mock.MockApiKey, nil)
attr, err := client.GetSegmentAttribution(segments)
assert.Equal(t, err, nil)
assert.True(t, len(attr[0].Metrics) == 5)
assert.True(t, len(attr[1].Metrics) == 5)
}
func TestGetSegmentCollection(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
mock.RegisterSegmentMocks()
client := NewLytics(mock.MockApiKey, nil)
collection, err := client.GetSegmentCollection(mock.MockSegmentCollection)
assert.Equal(t, err, nil)
assert.Equal(t, collection.Slug, "goal_funnel")
assert.True(t, len(collection.Collection) == 2)
assert.Equal(t, collection.Collection[0].Id, mock.MockSegmentID1)
assert.Equal(t, collection.Collection[1].Id, mock.MockSegmentID2)
}
func TestGetSegmentCollectionList(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
mock.RegisterSegmentMocks()
client := NewLytics(mock.MockApiKey, nil)
collections, err := client.GetSegmentCollectionList()
assert.Equal(t, err, nil)
assert.True(t, len(collections) == 2)
assert.Equal(t, collections[0].Slug, "goal_funnel")
assert.True(t, len(collections[0].Collection) == 2)
assert.Equal(t, collections[1].Slug, "mobile")
assert.True(t, len(collections[1].Collection) == 3)
}
func TestSegmentPager(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
mock.RegisterSegmentMocks()
var (
completed bool
countEntities int
)
client := NewLytics(mock.MockApiKey, nil)
// start the paging routine
scan := client.PageSegmentId(mock.MockSegmentID1)
assert.Equal(t, nil, scan.Err())
// handle processing the entities
for {
e := scan.Next()
if e == nil {
completed = true
break
}
countEntities++
assert.Equal(t, e.Fields["email"], fmt.Sprintf("email%[email protected]", countEntities))
}
assert.Equal(t, countEntities, 13)
assert.Equal(t, completed, true)
t.Logf("*** COMPLETED SCAN: %d total entities", scan.Total)
}
func TestCreateSegment(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
mock.RegisterSegmentMocks()
client := NewLytics(mock.MockApiKey, nil)
ql := "FILTER AND (created >= \"now-30d\", aspects = \"articles\") FROM content"
seg, err := client.CreateSegment("Recent Articles", ql, "recent_articles")
assert.Equal(t, err, nil)
assert.True(t, seg.Id != "")
assert.Equal(t, seg.FilterQL, ql)
seg, err = client.CreateSegment("Invalid Segment", "", "invalid")
assert.NotEqual(t, err, nil)
}
func TestValidateSegment(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
mock.RegisterSegmentMocks()
client := NewLytics(mock.MockApiKey, nil)
valid, err := client.ValidateSegment("FILTER AND (created >= \"now-30d\", aspects = \"articles\") FROM content")
assert.Equal(t, err, nil)
assert.True(t, valid)
valid, err = client.ValidateSegment("")
assert.NotEqual(t, err, nil)
assert.True(t, !valid)
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.