Skip to content

Commit

Permalink
feat(fetch): include mason.nvim version in User-Agent (#1362)
Browse files Browse the repository at this point in the history
  • Loading branch information
williamboman authored Jun 21, 2023
1 parent f7f81ab commit e706d30
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lua/mason-core/fetch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ local log = require "mason-core.log"
local platform = require "mason-core.platform"
local powershell = require "mason-core.managers.powershell"
local spawn = require "mason-core.spawn"
local version = require "mason.version"

local USER_AGENT = "mason.nvim (+https://github.com/williamboman/mason.nvim)"
local USER_AGENT = ("mason.nvim %s (+https://github.com/williamboman/mason.nvim)"):format(version.VERSION)

---@alias FetchMethod
---| '"GET"'
Expand Down
17 changes: 13 additions & 4 deletions tests/mason-core/fetch_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local fetch = require "mason-core.fetch"
local match = require "luassert.match"
local spawn = require "mason-core.spawn"
local stub = require "luassert.stub"
local version = require "mason.version"

describe("fetch", function()
it(
Expand All @@ -21,7 +22,9 @@ describe("fetch", function()
assert.spy(spawn.curl).was_called(1)
assert.spy(spawn.wget).was_called_with {
{
"--header=User-Agent: mason.nvim (+https://github.com/williamboman/mason.nvim)",
("--header=User-Agent: mason.nvim %s (+https://github.com/williamboman/mason.nvim)"):format(
version.VERSION
),
"--header=X-Custom-Header: here",
},
"-nv",
Expand All @@ -38,7 +41,9 @@ describe("fetch", function()
match.same {
{
"-H",
"User-Agent: mason.nvim (+https://github.com/williamboman/mason.nvim)",
("User-Agent: mason.nvim %s (+https://github.com/williamboman/mason.nvim)"):format(
version.VERSION
),
},
{
"-H",
Expand Down Expand Up @@ -79,7 +84,9 @@ describe("fetch", function()

assert.spy(spawn.wget).was_called_with {
{
"--header=User-Agent: mason.nvim (+https://github.com/williamboman/mason.nvim)",
("--header=User-Agent: mason.nvim %s (+https://github.com/williamboman/mason.nvim)"):format(
version.VERSION
),
},
"-nv",
"-o",
Expand All @@ -95,7 +102,9 @@ describe("fetch", function()
match.same {
{
"-H",
"User-Agent: mason.nvim (+https://github.com/williamboman/mason.nvim)",
("User-Agent: mason.nvim %s (+https://github.com/williamboman/mason.nvim)"):format(
version.VERSION
),
},
},
"-fsSL",
Expand Down

0 comments on commit e706d30

Please sign in to comment.