forked from ipfs/kubo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion_test.go
More file actions
79 lines (73 loc) · 2.02 KB
/
version_test.go
File metadata and controls
79 lines (73 loc) · 2.02 KB
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
package ipfs
import (
"testing"
"github.com/stretchr/testify/assert"
)
// TestGetUserAgentVersion verifies the user agent string used in libp2p
// identify and HTTP requests. Tagged release builds (where the commit matches
// the tag) skip the commit hash from the agent version, since the version
// number already identifies the exact source.
func TestGetUserAgentVersion(t *testing.T) {
origCommit := CurrentCommit
origTagged := taggedRelease
origSuffix := userAgentSuffix
t.Cleanup(func() {
CurrentCommit = origCommit
taggedRelease = origTagged
userAgentSuffix = origSuffix
})
tests := []struct {
name string
commit string
tagged string
suffix string
expected string
}{
// dev builds without ldflags
{
name: "no commit, no suffix",
expected: "kubo/" + CurrentVersionNumber,
},
// dev builds with commit set via ldflags
{
name: "with commit",
commit: "abc1234",
expected: "kubo/" + CurrentVersionNumber + "/abc1234",
},
{
name: "with suffix, no commit",
suffix: "test-suffix",
expected: "kubo/" + CurrentVersionNumber + "/test-suffix",
},
{
name: "with commit and suffix",
commit: "abc1234",
suffix: "test-suffix",
expected: "kubo/" + CurrentVersionNumber + "/abc1234/test-suffix",
},
// tagged release builds: commit is redundant because the version
// number already maps to an exact git tag, so it is omitted to
// save bytes in identify and HTTP user-agent headers.
{
name: "tagged release ignores commit",
commit: "abc1234",
tagged: "1",
expected: "kubo/" + CurrentVersionNumber,
},
{
name: "tagged release with suffix ignores commit",
commit: "abc1234",
tagged: "1",
suffix: "test-suffix",
expected: "kubo/" + CurrentVersionNumber + "/test-suffix",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
CurrentCommit = tt.commit
taggedRelease = tt.tagged
SetUserAgentSuffix(tt.suffix)
assert.Equal(t, tt.expected, GetUserAgentVersion())
})
}
}