Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions lua/gluatest/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
RunClientsideConVar = CreateConVar( "gluatest_client_enable", "0", conVarFlags, "Should GLuaTest run automatically on the client side?" ),
--- @diagnostic disable-next-line: param-type-mismatch
SelfTestConVar = CreateConVar( "gluatest_selftest_enable", "0", conVarFlags, "Should GLuaTest run its own tests?" ),
--- @diagnostic disable-next-line: param-type-mismatch
HttpHelloConVar = CreateConVar( "gluatest_http_hello", "1", conVarFlags, "Should GLuaTest ping the GLuaTest hello endpoint?" ),

DeprecatedNotice = function( old, new )
local msg = [[GLuaTest: (DEPRECATION NOTICE) "]] .. old .. [[" is deprecated, use "]] .. new .. [[" instead.]]
Expand Down Expand Up @@ -80,6 +82,33 @@
end
end

--- Encodes a string for use in a URL param
--- @param str string
local function urlEncode( str )
if not str then return "" end

str = string.gsub( str, "([^%w%-%._~])", function( c )
return string.format( "%%%02X", string.byte( c ) )
end )

return str
end

--- Runs a simple ping against the GLuatest Hello endpoint
--- (Helps us get a rough idea of how many people use GLuaTest, as well as preserving HTTP during container minification)
--- @param version string
local function httpHello( version )
local shouldRun = GLuaTest.HttpHello:GetBool()

Check warning on line 101 in lua/gluatest/init.lua

View workflow job for this annotation

GitHub Actions / luals / check

undefined-field

Undefined field `HttpHello`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be HttpHelloConVar xd

if not shouldRun then return end

HTTP( {
method = "GET",
url = "https://hello.gluatest.com?version=" .. urlEncode( version ),
success = function() end,
failed = function() end,
} )

Check warning on line 109 in lua/gluatest/init.lua

View workflow job for this annotation

GitHub Actions / luals / check

missing-fields

Missing required fields in type `HTTPRequest`: `parameters`, `body`, `timeout`, `type`, `headers`
end

--- @param loader GLuaTest_Loader
--- @param projectName string
--- @param path string
Expand Down Expand Up @@ -147,6 +176,8 @@

hook.Run( "GLuaTest_RunTestFiles", testFiles )

httpHello( GLuaTest.VERSION )

--- @type GLuaTest_TestRunner
local runner = include( "gluatest/runner/runner.lua" )
runner:Run( testFiles )
Expand Down
Loading