Last active
July 7, 2024 12:02
-
-
Save Bilal2453/e7f11269aa9276db40f2c1e806733038 to your computer and use it in GitHub Desktop.
proposing some lit tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local fs = require 'coro-fs' | |
local uv = require 'uv' | |
local join = require 'pathjoin'.pathJoin | |
local makeCore = require 'core' | |
local DB_PATH = "./lit-install-db" | |
local TEST_PKG_NAME = 'coro-channel' | |
local TEST_PKG_FULLNAME = 'creationix/coro-channel@3.0.0' | |
local TEST_PKG_LATEST = '3.0.3' | |
local TEST_PKG_HASH = '89058f66303e71e1f6dbdf7cbe7e54cb8159b53c\n' | |
local core = makeCore{ | |
database = DB_PATH, | |
upstream = "wss://lit.luvit.io/", | |
} | |
require('tap')(function (test) | |
test('install coro-channel', function() | |
-- try to install the package with a major version | |
-- the version we get installed should be 3.0.3 | |
local deps = core.installList(uv.cwd(), {TEST_PKG_FULLNAME}) | |
assert(deps, 'core.installList failed with return ' .. tostring(deps)) | |
-- is the reported installed version match our expectations? | |
local ver = deps[TEST_PKG_NAME].version | |
assert(ver == TEST_PKG_LATEST, 'expected version ' .. TEST_PKG_LATEST .. ', got instead ' .. ver) | |
local refPath = join(DB_PATH, '/refs/tags/creationix/coro-channel/v', TEST_PKG_LATEST) | |
-- is the supposedly created tag accessible? | |
local canAccess = fs.access(refPath, 'rw') | |
if not canAccess then | |
-- does it actually exists? | |
assert(fs.stat(refPath), 'tag ref does not exists at ' .. refPath) | |
-- otherwise we were unable to access it because of insufficient permissions | |
error('cannot access tag ref for read and write' .. refPath) | |
end | |
-- can we read the contents of the tag ref? | |
local content = assert(fs.readFile(refPath)) | |
-- does the blob hash match our expectations? | |
assert(content == TEST_PKG_HASH, 'invalid hash on ' .. refPath) | |
-- TODO: test if the actual downloaded package matches the blob hash | |
-- can we access the library we just installed? | |
local depsPath = join(uv.cwd(), 'deps') | |
local pkgPath = join(depsPath, TEST_PKG_NAME .. '.lua') | |
canAccess = fs.access(pkgPath, 'rw') | |
if not canAccess then | |
-- does the deps directory actually exists? | |
assert(fs.stat(depsPath), 'deps directory not found at ' .. depsPath) | |
-- does the file we are expecting exists? | |
assert(fs.stat(pkgPath), 'package file not found at ' .. pkgPath) | |
-- at this point the only possible scenario is we don't have sufficient permission | |
error('insufficient permission on ' .. pkgPath) | |
end | |
end) | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment