Path: blob/main/libexec/nuageinit/tests/addfile.lua
35072 views
#!/bin/libexec/flua12local n = require("nuage")3local lfs = require("lfs")45local f = {6content = "plop"7}89local r, err = n.addfile(f, false)10if r or err ~= "No path provided for the file to write" then11n.err("addfile should not accept a file to write without a path")12end1314local function addfile_and_getres(file)15local r, err = n.addfile(file, false)16if not r then17n.err(err)18end19local root = os.getenv("NUAGE_FAKE_ROOTDIR")20if not root then21root = ""22end23local filepath = root .. file.path24local resf = assert(io.open(filepath, "r"))25local str = resf:read("*all")26resf:close()27return str28end2930-- simple file31f.path="/tmp/testnuage"32local str = addfile_and_getres(f)33if str ~= f.content then34n.err("Invalid file content")35end3637-- the file is overwriten38f.content = "test"3940str = addfile_and_getres(f)41if str ~= f.content then42n.err("Invalid file content, not overwritten")43end4445-- try to append now46f.content = "more"47f.append = true4849str = addfile_and_getres(f)50if str ~= "test" .. f.content then51n.err("Invalid file content, not appended")52end5354-- base6455f.content = "YmxhCg=="56f.encoding = "base64"57f.append = false5859str = addfile_and_getres(f)60if str ~= "bla\n" then61n.err("Invalid file content, base64 decode")62end6364-- b6465f.encoding = "b64"66str = addfile_and_getres(f)67if str ~= "bla\n" then68n.err("Invalid file content, b64 decode")69print("==>" .. str .. "<==")70end717273