Merge pull request #733 from clusterio/feature/subspace-storage-space-age

Feature/subspace storage space age
This commit is contained in:
Daniel authored and GitHub committed 2025-02-25 18:53:36 +01:00
commit a16dcd315f
15 files changed
+249 -186

No files matched your search

+7 -3
View File
@@ -199,12 +199,16 @@ describe("Integration of Clusterio", function() {
it("should download mods from controller", async function() {
slowTest(this);
await runWithAltHost(async () => {
const clusterioLib = path.join("temp", "test", "alt-mods", "clusterio_lib_0.1.2.zip");
assert(!await fs.pathExists(clusterioLib), "mod was downloaded before the test");
// Use the latest vesion in /dist instead of a hardcoded version
async function checkModDownloaded() {
let files = await fs.readdir(path.join("temp", "test", "alt-mods"));
return files.find(name => name.startsWith("clusterio_lib_"));
}
assert(!await checkModDownloaded(), "mod was downloaded before the test");
await execCtl("instance create alt-mod --id 98");
await execCtl("instance assign alt-mod 5");
await execCtl("instance save create alt-mod");
assert(await fs.pathExists(clusterioLib), "mod was not downloaded by the test");
assert(await checkModDownloaded(), "mod was not downloaded by the test");
});
});
it("should auto start instances with auto_start enabled", async function() {
+2 -24
View File
@@ -18,9 +18,6 @@ require("../../plugins/research_sync/dist/node/index");
require("../../plugins/statistics_exporter/dist/node/index");
require("../../plugins/subspace_storage/dist/node/index");
const subspaceStorageVersion = "1.99.8";
const subspaceStorageGitHubTag = "1.99.6"; // Tag subspaceStorageVersion was released under on GitHub
class TestControl extends lib.Link {
constructor(connector, subscribe = true) {
super(connector);
@@ -266,24 +263,6 @@ before(async function() {
sourceDir: "packages/host/lua/clusterio_lib",
outputDir: modsDir,
});
const ssv = subspaceStorageVersion;
const ssTag = subspaceStorageGitHubTag;
const ssZip = `subspace_storage_${ssv}.zip`;
if (!await fs.pathExists(`mods/${ssZip}`)) {
console.log(`Downloading ${ssZip}`);
const ssUrl = `https://github.com/clusterio/subspace_storage/releases/download/${ssTag}/${ssZip}`;
let response = await phin({
url: ssUrl,
method: "GET",
stream: false, // phin leaks open sockets when stream and followRedirects is combined
followRedirects: true,
});
if (response.statusCode !== 200) {
throw new Error(`${ssUrl} returned ${response.statusCode} ${response.statusMessage}`);
}
await fs.outputFile(`mods/${ssZip}`, response.body);
}
await fs.copyFile(`mods/${ssZip}`, `${modsDir}/${ssZip}`);
console.log("Setting Controller Config");
await exec("node ../../packages/controller config set controller.auth_secret TestSecretDoNotUse");
@@ -325,9 +304,8 @@ before(async function() {
const testPack = lib.ModPack.fromJSON({});
testPack.id = 12;
testPack.name = "subspace_storage-pack";
testPack.factorioVersion = "1.1.0";
testPack.mods.set("clusterio_lib", { name: "clusterio_lib", enabled: true, version: "0.1.2" });
testPack.mods.set("subspace_storage", { name: "subspace_storage", enabled: true, version: subspaceStorageVersion });
testPack.factorioVersion = "2.0.0";
testPack.mods.set("clusterio_lib", { name: "clusterio_lib", enabled: true, version: "2.0.20" });
await control.sendTo("controller", new lib.ModPackCreateRequest(testPack));
await control.sendTo(
"controller",
+2 -4
View File
@@ -27,8 +27,7 @@ describe("lib/data/ModPack", function() {
check(ModPack.fromJSON({ description: "My Description" }));
check(ModPack.fromJSON({ factorio_version: "2.0" }));
check(ModPack.fromJSON({ mods: [
{ name: "subspace_storage", enabled: true, version: "1.99.8" },
{ name: "clusterio_lib", enabled: true, version: "0.1.2", sha1: "012345abcd" },
{ name: "clusterio_lib", enabled: true, version: "2.0.20", sha1: "012345abcd" },
]}));
check(ModPack.fromJSON({ settings: {
"startup": {
@@ -49,8 +48,7 @@ describe("lib/data/ModPack", function() {
description: "Every option at once.",
factorio_version: "2.0",
mods: [
{ name: "subspace_storage", enabled: true, version: "1.99.8" },
{ name: "clusterio_lib", enabled: true, version: "0.1.2", sha1: "012345abcd" },
{ name: "clusterio_lib", enabled: true, version: "2.0.20", sha1: "012345abcd" },
],
settings: {
"startup": {
+19 -19
View File
@@ -169,7 +169,7 @@ describe("lib/database", function() {
it("should restore the passed serialized database", function() {
let items = new lib.ItemDatabase({ "a": 1, "b": 2 });
assert.deepEqual(items._items, new Map([["a", 1], ["b", 2]]));
assert.deepEqual(items._items, new Map([["a", { normal: 1 }], ["b", { normal: 2 }]]));
});
it("should throw on invalid serialized database", function() {
@@ -188,7 +188,7 @@ describe("lib/database", function() {
describe(".serialize()", function() {
it("should return a serialized database", function() {
let items = new lib.ItemDatabase({ "a": 10 });
assert.deepEqual(items.serialize(), { "a": 10 });
assert.deepEqual(items.serialize(), { "a": { normal: 10 } });
});
it("should remove zero count entries", function() {
@@ -207,18 +207,18 @@ describe("lib/database", function() {
describe(".getItemCount()", function() {
it("should return the count of the given item", function() {
let items = new lib.ItemDatabase({ "a": 10 });
assert.equal(items.getItemCount("a"), 10);
assert.equal(items.getItemCount("a", "normal"), 10);
});
it("should return zero if item does not exist", function() {
let items = new lib.ItemDatabase();
assert.equal(items.getItemCount("b"), 0);
assert.equal(items.getItemCount("b", "normal"), 0);
});
it("should throw on invalid name", function() {
let items = new lib.ItemDatabase();
assert.throws(
() => items.getItemCount(2),
() => items.getItemCount(2, "normal"),
new Error("name must be a string")
);
});
@@ -227,20 +227,20 @@ describe("lib/database", function() {
describe(".addItem()", function() {
it("should add a new item", function() {
let items = new lib.ItemDatabase();
items.addItem("a", 10);
assert.deepEqual(items._items, new Map([["a", 10]]));
items.addItem("a", 10, "normal");
assert.deepEqual(items._items, new Map([["a", { normal: 10 }]]));
});
it("should add an existing item", function() {
let items = new lib.ItemDatabase({ "a": 10 });
items.addItem("a", 10);
assert.deepEqual(items._items, new Map([["a", 20]]));
items.addItem("a", 10, "normal");
assert.deepEqual(items._items, new Map([["a", { normal: 20 }]]));
});
it("should throw on invalid name", function() {
let items = new lib.ItemDatabase();
assert.throws(
() => items.addItem(2, 10),
() => items.addItem(2, 10, "normal"),
new Error("name must be a string")
);
});
@@ -248,11 +248,11 @@ describe("lib/database", function() {
it("should throw on invalid count", function() {
let items = new lib.ItemDatabase();
assert.throws(
() => items.addItem("a", NaN),
() => items.addItem("a", NaN, "normal"),
new Error("count must be a number")
);
assert.throws(
() => items.addItem("a", "1"),
() => items.addItem("a", "1", "normal"),
new Error("count must be a number")
);
});
@@ -261,20 +261,20 @@ describe("lib/database", function() {
describe(".removeItem()", function() {
it("should remove an existing item", function() {
let items = new lib.ItemDatabase({ "a": 20 });
items.removeItem("a", 10);
assert.deepEqual(items._items, new Map([["a", 10]]));
items.removeItem("a", 10, "normal");
assert.deepEqual(items._items, new Map([["a", { normal: 10 }]]));
});
it("should turn a non-existing item negative", function() {
let items = new lib.ItemDatabase();
items.removeItem("a", 10);
assert.deepEqual(items._items, new Map([["a", -10]]));
items.removeItem("a", 10, "normal");
assert.deepEqual(items._items, new Map([["a", { normal: -10 }]]));
});
it("should throw on invalid name", function() {
let items = new lib.ItemDatabase();
assert.throws(
() => items.removeItem(2, 10),
() => items.removeItem(2, 10, "normal"),
new Error("name must be a string")
);
});
@@ -282,11 +282,11 @@ describe("lib/database", function() {
it("should throw on invalid count", function() {
let items = new lib.ItemDatabase();
assert.throws(
() => items.removeItem("a", "b"),
() => items.removeItem("a", "b", "normal"),
new Error("count must be a number")
);
assert.throws(
() => items.removeItem("a", "1"),
() => items.removeItem("a", "1", "normal"),
new Error("count must be a number")
);
});