Skip to content

Commit

Permalink
Adding Android to recognized UserAgent platform, expanding unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kenshaw committed Mar 31, 2024
1 parent 3013883 commit 9dd0666
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
6 changes: 4 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,20 @@ type Version struct {

// UserAgent builds a user agent for the platform.
func (ver Version) UserAgent(platform string) string {
typ := "Windows NT 10.0; Win64; x64"
typ, extra := "Windows NT 10.0; Win64; x64", ""
switch strings.ToLower(platform) {
case "linux":
typ = "X11; Linux x86_64"
case "mac", "mac_arm64":
typ = "Macintosh; Intel Mac OS X 10_15_7"
case "android":
typ, extra = "Linux; Android 10; K", " Mobile"
}
v := "120.0.0.0"
if i := strings.Index(ver.Version, "."); i != -1 {
v = ver.Version[:i] + ".0.0.0"
}
return fmt.Sprintf("Mozilla/5.0 (%s) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Safari/537.36", typ, v)
return fmt.Sprintf("Mozilla/5.0 (%s) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s%s Safari/537.36", typ, v, extra)
}

// Option is a version history client option.
Expand Down
32 changes: 21 additions & 11 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,16 @@ func TestLatest(t *testing.T) {
if os.Getenv("VERBOSE") != "" {
opts = append(opts, WithLogf(t.Logf))
}
latest, err := Latest(context.Background(), "win", "stable", opts...)
if err != nil {
t.Fatalf("expected no error, got: %v", err)
for _, channel := range []string{"stable", "beta", "dev"} {
t.Run(channel, func(t *testing.T) {
t.Parallel()
latest, err := Latest(context.Background(), "win64", channel, opts...)
if err != nil {
t.Fatalf("expected no error, got: %v", err)
}
t.Logf("name: %s version: %s", latest.Name, latest.Version)
})
}
t.Logf("name: %s version: %s", latest.Name, latest.Version)
}

func TestUserAgent(t *testing.T) {
Expand All @@ -75,14 +80,19 @@ func TestUserAgent(t *testing.T) {
if os.Getenv("VERBOSE") != "" {
opts = append(opts, WithLogf(t.Logf))
}
userAgent, err := UserAgent(context.Background(), "linux", "stable", opts...)
switch {
case err != nil:
t.Fatalf("expected no error, got: %v", err)
case userAgent == "":
t.Errorf("expected non-empty user agent")
for _, platform := range []string{"win64", "mac_arm64", "linux", "android"} {
t.Run(platform, func(t *testing.T) {
t.Parallel()
userAgent, err := UserAgent(context.Background(), platform, "stable", opts...)
switch {
case err != nil:
t.Fatalf("expected no error, got: %v", err)
case userAgent == "":
t.Errorf("expected non-empty user agent")
}
t.Logf("user agent: %v", userAgent)
})
}
t.Logf("user agent: %v", userAgent)
}

func platforms() []PlatformType {
Expand Down

0 comments on commit 9dd0666

Please sign in to comment.