-
Notifications
You must be signed in to change notification settings - Fork 301
/
analytics_test.go
56 lines (47 loc) · 1.32 KB
/
analytics_test.go
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
package analytics
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/tilt-dev/wmclient/pkg/analytics"
"github.com/tilt-dev/tilt/internal/tiltfile/starkit"
)
func TestEmpty(t *testing.T) {
f := NewFixture(t)
f.File("Tiltfile", `
`)
result, err := f.ExecFile("Tiltfile")
assert.NoError(t, err)
assert.Equal(t, analytics.OptDefault, MustState(result).Opt)
}
func TestEnableTrue(t *testing.T) {
f := NewFixture(t)
f.File("Tiltfile", `
analytics_settings(enable=True)
`)
result, err := f.ExecFile("Tiltfile")
assert.NoError(t, err)
assert.Equal(t, analytics.OptIn, MustState(result).Opt)
}
func TestEnableFalse(t *testing.T) {
f := NewFixture(t)
f.File("Tiltfile", `
analytics_settings(enable=False)
`)
result, err := f.ExecFile("Tiltfile")
assert.NoError(t, err)
assert.Equal(t, analytics.OptOut, MustState(result).Opt)
}
func TestReportToAnalytics(t *testing.T) {
f := NewFixture(t)
f.File("Tiltfile", `
experimental_analytics_report({'1': '2'})
# the second call's "1" value replaces the first
experimental_analytics_report({'1': '2a', '3': '4'})
`)
result, err := f.ExecFile("Tiltfile")
assert.NoError(t, err)
assert.Equal(t, map[string]string{"1": "2a", "3": "4"}, MustState(result).CustomTagsToReport)
}
func NewFixture(tb testing.TB) *starkit.Fixture {
return starkit.NewFixture(tb, NewExtension())
}