-
Notifications
You must be signed in to change notification settings - Fork 213
/
util_test.go
99 lines (83 loc) · 2.04 KB
/
util_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
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
package sentry
import (
"runtime/debug"
"testing"
)
func TestUUIDReturnsRandom32CharacterString(t *testing.T) {
u1 := uuid()
u2 := uuid()
u3 := uuid()
assertEqual(t, len(u1), 32)
assertEqual(t, len(u2), 32)
assertEqual(t, len(u3), 32)
assertNotEqual(t, u1, u2)
assertNotEqual(t, u1, u3)
assertNotEqual(t, u2, u3)
}
func TestFileExistsReturnsTrueForExistingFiles(t *testing.T) {
assertEqual(t, fileExists(("util.go")), true)
assertEqual(t, fileExists(("util_test.go")), true)
}
func TestFileExistsReturnsFalseForNonExistingFiles(t *testing.T) {
assertEqual(t, fileExists(("util_nope.go")), false)
assertEqual(t, fileExists(("util_nope_test.go")), false)
}
func TestDefaultReleaseSentryReleaseEnvvar(t *testing.T) {
releaseVersion := "1.2.3"
t.Setenv("SENTRY_RELEASE", releaseVersion)
assertEqual(t, defaultRelease(), releaseVersion)
}
func TestDefaultReleaseSentryReleaseEnvvarPrecedence(t *testing.T) {
releaseVersion := "1.2.3"
t.Setenv("SOURCE_VERSION", "3.2.1")
t.Setenv("SENTRY_RELEASE", releaseVersion)
assertEqual(t, defaultRelease(), releaseVersion)
}
func TestRevisionFromBuildInfo(t *testing.T) {
releaseVersion := "deadbeef"
info := &debug.BuildInfo{
Main: debug.Module{
Path: "my/module",
Version: "(devel)",
},
Deps: []*debug.Module{
{
Path: "github.com/getsentry/sentry-go",
Version: "v0.23.1",
Replace: &debug.Module{
Path: "pkg/sentry",
},
},
},
Settings: []debug.BuildSetting{
{
Key: "vcs.revision",
Value: releaseVersion,
},
},
}
assertEqual(t, revisionFromBuildInfo(info), releaseVersion)
}
func TestRevisionFromBuildInfoNoVcsInformation(t *testing.T) {
info := &debug.BuildInfo{
Main: debug.Module{
Path: "my/module",
Version: "(devel)",
},
Deps: []*debug.Module{
{
Path: "github.com/getsentry/sentry-go",
Version: "v0.23.1",
Replace: &debug.Module{
Path: "pkg/sentry",
},
},
},
}
assertEqual(t, revisionFromBuildInfo(info), "")
}
func TestPointer(t *testing.T) {
i := 5
v := Pointer(i)
assertEqual(t, *v, i)
}