Repository navigation
Expand file tree
/
Copy pathidentity_test.go
More file actions
53 lines (45 loc) · 1.69 KB
/
Copy pathidentity_test.go
File metadata and controls
53 lines (45 loc) · 1.69 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
package gitsync
import (
"testing"
"entire.io/entire/git-sync/internal/useragent"
"github.com/go-git/go-git/v6/plumbing/protocol/capability"
)
func TestSetIdentity(t *testing.T) {
// Not parallel — mutates process-wide user-agent state.
orig := useragent.Identity
t.Cleanup(func() { useragent.Identity = orig })
tests := []struct {
name string
service, version string
wantIdentity string
}{
{"service and version", "mirror-worker", "abc1234", "mirror-worker/abc1234"},
{"service only", "mirror-worker", "", "mirror-worker"},
{"empty service clears", "", "abc1234", ""},
{"whitespace collapsed", "mirror worker", "v1 2", "mirror-worker/v1-2"},
{"blank service clears", " ", "abc1234", ""},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
SetIdentity(tt.service, tt.version)
if useragent.Identity != tt.wantIdentity {
t.Errorf("SetIdentity(%q, %q) → Identity = %q, want %q",
tt.service, tt.version, useragent.Identity, tt.wantIdentity)
}
})
}
}
func TestSetIdentityUserAgentShape(t *testing.T) {
// Not parallel — mutates process-wide user-agent state.
origIdentity, origVersion := useragent.Identity, useragent.Version
t.Cleanup(func() { useragent.Identity, useragent.Version = origIdentity, origVersion })
useragent.Version = "0.7.1"
SetIdentity("mirror-worker", "abc1234")
want := "mirror-worker/abc1234 git-sync/0.7.1 " + capability.DefaultAgent()
if got := useragent.GoGit(); got != want {
t.Errorf("GoGit() after SetIdentity = %q, want %q", got, want)
}
if got, want := useragent.Plain(), "mirror-worker/abc1234 git-sync/0.7.1"; got != want {
t.Errorf("Plain() after SetIdentity = %q, want %q", got, want)
}
}