nuageinit: add decode_base64 tests

This commit is contained in:
Baptiste Daroussin
2026-05-07 19:17:56 +02:00
parent 428da7d65b
commit 68fd0feacb
3 changed files with 70 additions and 0 deletions
+1
View File
@@ -18,5 +18,6 @@ ${PACKAGE}FILES+= sethostname.lua
${PACKAGE}FILES+= settimezone.lua
${PACKAGE}FILES+= warn.lua
${PACKAGE}FILES+= addfile.lua
${PACKAGE}FILES+= decode_base64.lua
.include <bsd.test.mk>
+61
View File
@@ -0,0 +1,61 @@
#!/usr/libexec/flua
---
-- SPDX-License-Identifier: BSD-2-Clause
--
-- Copyright (c) 2026 Baptiste Daroussin <bapt@FreeBSD.org>
local n = require("nuage")
-- decode_base64 is not exported, test via addfile
local function test_decode(input, expected)
local r, err = n.addfile({
content = input,
encoding = "base64",
path = "/tmp/nuage_test_b64"
}, false)
if not r then
n.err(err)
end
local root = os.getenv("NUAGE_FAKE_ROOTDIR")
if not root then
root = ""
end
local f = assert(io.open(root .. "/tmp/nuage_test_b64", "r"))
local str = f:read("*all")
f:close()
if str ~= expected then
n.err("base64 decode failed: expected '" .. expected
.. "' got '" .. str .. "'")
end
end
-- empty input
test_decode("", "")
-- single byte: 'a'
test_decode("YQ==", "a")
-- two bytes: 'ab'
test_decode("YWI=", "ab")
-- three bytes: 'abc'
test_decode("YWJj", "abc")
-- newline in base64
test_decode("YmxhCg==", "bla\n")
-- spaces should be ignored
test_decode("Y Q = =", "a")
-- b64 alias
local r, err = n.addfile({
content = "YQ==",
encoding = "b64",
path = "/tmp/nuage_test_b64_b64"
}, false)
if not r then
n.err("b64 encoding alias should work: " .. tostring(err))
end
os.exit(0)
+8
View File
@@ -14,6 +14,7 @@ atf_test_case adduser
atf_test_case adduser_passwd
atf_test_case addgroup
atf_test_case addfile
atf_test_case decode_base64
settimezone_body()
{
@@ -90,6 +91,12 @@ addfile_body()
atf_check /usr/libexec/flua $(atf_get_srcdir)/addfile.lua
}
decode_base64_body()
{
mkdir tmp
atf_check /usr/libexec/flua $(atf_get_srcdir)/decode_base64.lua
}
atf_init_test_cases()
{
atf_add_test_case sethostname
@@ -98,4 +105,5 @@ atf_init_test_cases()
atf_add_test_case adduser_passwd
atf_add_test_case addgroup
atf_add_test_case addfile
atf_add_test_case decode_base64
}