mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 07:33:12 +09:00
Add shared mods management
Add the ability to manage a set of mods to be shared by the master server to the rest of the cluster. This implements storage, uploads, downloads, deletetion, and listing details of mods but does not actually do anything with the stored mods.
This commit is contained in:
1 parent
2ab915cc00
commit
3b57c1e0ae
23 files changed
+1311
-5
No files matched your search
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "empty_mod",
|
||||
"version": "1.0.0",
|
||||
"title": "An Empty Mod",
|
||||
"author": "Me",
|
||||
"description": "An empty mod for testing",
|
||||
"factorio_version": "1.1",
|
||||
"dependencies": []
|
||||
}
|
||||
@@ -5,6 +5,8 @@ const path = require("path");
|
||||
const events = require("events");
|
||||
const phin = require("phin");
|
||||
|
||||
const libBuildMod = require("@clusterio/lib/build_mod");
|
||||
const libHash = require("@clusterio/lib/hash");
|
||||
const libLink = require("@clusterio/lib/link");
|
||||
const libUsers = require("@clusterio/lib/users");
|
||||
const { wait } = require("@clusterio/lib/helpers");
|
||||
@@ -818,6 +820,91 @@ describe("Integration of Clusterio", function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("mod upload", function() {
|
||||
it("uploads a mod", async function() {
|
||||
await libBuildMod.build({
|
||||
build: true,
|
||||
pack: true,
|
||||
sourceDir: path.join("test", "file", "empty_mod"),
|
||||
outputDir: path.join("temp", "test"),
|
||||
});
|
||||
await execCtl("mod upload empty_mod_1.0.0.zip");
|
||||
assert(
|
||||
await fs.pathExists(path.join("temp", "test", "mods", "empty_mod_1.0.0.zip")),
|
||||
"mod not present in mods directory"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("mod show", function() {
|
||||
it("gives details of a mod", async function() {
|
||||
let result = await execCtl("mod show empty_mod 1.0.0");
|
||||
let hash = await libHash.hashFile(path.join("temp", "test", "mods", "empty_mod_1.0.0.zip"));
|
||||
let stat = await fs.stat(path.join("temp", "test", "mods", "empty_mod_1.0.0.zip"));
|
||||
assert.equal(
|
||||
result.stdout,
|
||||
"name: empty_mod\n" +
|
||||
"version: 1.0.0\n" +
|
||||
"title: An Empty Mod\n" +
|
||||
"author: Me\n" +
|
||||
"description: An empty mod for testing\n" +
|
||||
"factorio_version: 1.1\n" +
|
||||
"dependencies:\n" +
|
||||
"filename: empty_mod_1.0.0.zip\n" +
|
||||
`size: ${stat.size}\n` +
|
||||
`hash: sha1:${hash}\n`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("mod list", function() {
|
||||
it("shows the list of mods", async function() {
|
||||
let result = await execCtl("mod list");
|
||||
assert(result.stdout.indexOf("empty_mod") !== -1, "empty_mod is not in the list");
|
||||
});
|
||||
});
|
||||
|
||||
describe("mod download", function() {
|
||||
it("downloads a mod", async function() {
|
||||
await fs.unlink(path.join("temp", "test", "empty_mod_1.0.0.zip"));
|
||||
await execCtl("mod download empty_mod 1.0.0");
|
||||
assert(
|
||||
await fs.pathExists(path.join("temp", "test", "empty_mod_1.0.0.zip")),
|
||||
"mod not downloaded to cwd"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("mod delete", function() {
|
||||
it("deletes a mod", async function() {
|
||||
await execCtl("mod delete empty_mod 1.0.0");
|
||||
assert(
|
||||
!await fs.pathExists(path.join("temp", "test", "mods", "empty_mod_1.0.0.zip")),
|
||||
"mod still present in mods dir"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("modUpdateEventHandler()", function() {
|
||||
it("should have triggered for the previous mod updates", function() {
|
||||
let eventsToCheck = new Set(["updated", "deleted"]);
|
||||
let eventsNotSeen = new Set(eventsToCheck);
|
||||
|
||||
for (let modUpdate of getControl().modUpdates) {
|
||||
if (modUpdate.name !== "empty_mod" || modUpdate.version !== "1.0.0") {
|
||||
continue;
|
||||
}
|
||||
if (modUpdate.is_deleted) {
|
||||
eventsNotSeen.delete("deleted");
|
||||
} else {
|
||||
eventsNotSeen.delete("updated");
|
||||
}
|
||||
}
|
||||
|
||||
assert(eventsNotSeen.size === 0, `Did not see the events ${[...eventsNotSeen]}`);
|
||||
});
|
||||
});
|
||||
|
||||
describe("permission list", function() {
|
||||
it("runs", async function() {
|
||||
await execCtl("permission list");
|
||||
|
||||
@@ -28,6 +28,7 @@ class TestControl extends libLink.Link {
|
||||
this.slaveUpdates = [];
|
||||
this.instanceUpdates = [];
|
||||
this.saveListUpdates = [];
|
||||
this.modUpdates = [];
|
||||
this.userUpdates = [];
|
||||
|
||||
this.connector.on("connect", () => {
|
||||
@@ -40,6 +41,9 @@ class TestControl extends libLink.Link {
|
||||
libLink.messages.setSaveListSubscriptions.send(
|
||||
this, { all: true, instance_ids: [] }
|
||||
).catch(err => logger.error(`Error setting save list subscriptions:\n${err.stack}`));
|
||||
libLink.messages.setModSubscriptions.send(
|
||||
this, { all: true, mod_names: [] }
|
||||
).catch(err => logger.error(`Error setting mod subscriptions:\n${err.stack}`));
|
||||
libLink.messages.setUserSubscriptions.send(
|
||||
this, { all: true, names: [] }
|
||||
).catch(err => logger.error(`Error setting user subscriptions:\n${err.stack}`));
|
||||
@@ -67,6 +71,10 @@ class TestControl extends libLink.Link {
|
||||
this.saveListUpdates.push(message.data);
|
||||
}
|
||||
|
||||
async modUpdateEventHandler(message) {
|
||||
this.modUpdates.push(message.data.mod);
|
||||
}
|
||||
|
||||
async userUpdateEventHandler(message) {
|
||||
this.userUpdates.push(message.data);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
|
||||
const libSchema = require("@clusterio/lib/schema");
|
||||
const libHash = require("@clusterio/lib/hash");
|
||||
const libBuildMod = require("@clusterio/lib/build_mod");
|
||||
const ModInfo = require("@clusterio/lib/data/ModInfo");
|
||||
|
||||
|
||||
describe("lib/data/ModInfo", function() {
|
||||
describe("class ModInfo", function() {
|
||||
it("should round trip serialize", function() {
|
||||
const validate = libSchema.compile(ModInfo.jsonSchema);
|
||||
function check(pack) {
|
||||
const json = JSON.parse(JSON.stringify(pack));
|
||||
if (!validate(json)) {
|
||||
throw validate.errors;
|
||||
}
|
||||
assert.deepEqual(new ModInfo(json), pack);
|
||||
}
|
||||
|
||||
check(new ModInfo());
|
||||
check(new ModInfo({ name: "MyMod" }));
|
||||
check(new ModInfo({ version: "1.0.0" }));
|
||||
check(new ModInfo({ title: "My Extravagent Mod" }));
|
||||
check(new ModInfo({ author: "Me" }));
|
||||
check(new ModInfo({ contact: "Use my email" }));
|
||||
check(new ModInfo({ homepage: "It's over there" }));
|
||||
check(new ModInfo({ description: "My Description" }));
|
||||
check(new ModInfo({ factorio_version: "2.0" }));
|
||||
check(new ModInfo({ dependencies: [] }));
|
||||
check(new ModInfo({ dependencies: ["UltraMod", "SuperLib >= 1.00", "! bad-mod"] }));
|
||||
check(new ModInfo({ filename: "MyMod_1.0.0.zip" }));
|
||||
check(new ModInfo({ size: 1024 }));
|
||||
check(new ModInfo({ hash: "sha5:verified-as-MyMod" }));
|
||||
check(new ModInfo({ is_deleted: true }));
|
||||
|
||||
// All at once
|
||||
check(new ModInfo({
|
||||
name: "MyMod",
|
||||
version: "1.0.0",
|
||||
title: "My Extravagent Mod",
|
||||
author: "Me",
|
||||
contact: "Use my email",
|
||||
homepage: "It's over there",
|
||||
description: "My Description",
|
||||
factorio_version: "2.0",
|
||||
dependencies: ["UltraMod", "SuperLib >= 1.00", "! bad-mod"],
|
||||
filename: "MyMod_1.0.0.zip",
|
||||
size: 1024,
|
||||
hash: "sha5:verified-as-MyMod",
|
||||
is_deleted: true,
|
||||
}));
|
||||
});
|
||||
|
||||
it("should sort integer mod versions lexicographically", function() {
|
||||
let unsortedVersions = ["1.0.0", "1.1.0", "0.1.0", "3.0.0", "1.2.0", "0.3.1", "0.3.3", "2.1.1", "0.0.1"];
|
||||
let sortedVersions = ["0.0.1", "0.1.0", "0.3.1", "0.3.3", "1.0.0", "1.1.0", "1.2.0", "2.1.1", "3.0.0"];
|
||||
let mods = unsortedVersions.map(v => new ModInfo({ version: v }));
|
||||
mods.sort((a, b) => a.integerVersion - b.integerVersion);
|
||||
assert.deepEqual(mods.map(mod => mod.version), sortedVersions);
|
||||
});
|
||||
it("should sort integer factorio versions lexicographically", function() {
|
||||
let unsortedVersions = ["1.0", "1.1", "0.1", "3.0", "1.2", "0.3", "2.1"];
|
||||
let sortedVersions = ["0.1", "0.3", "1.0", "1.1", "1.2", "2.1", "3.0"];
|
||||
let factorioMods = unsortedVersions.map(v => new ModInfo({ factorio_version: v }));
|
||||
factorioMods.sort((a, b) => a.integerFactorioVersion - b.integerFactorioVersion);
|
||||
assert.deepEqual(factorioMods.map(mod => mod.factorioVersion), sortedVersions);
|
||||
});
|
||||
|
||||
it("should load from a mod zip file", async function() {
|
||||
await libBuildMod.build({
|
||||
build: true,
|
||||
pack: true,
|
||||
sourceDir: path.join("test", "file", "empty_mod"),
|
||||
outputDir: path.join("temp", "test"),
|
||||
});
|
||||
const filePath = path.join("temp", "test", "empty_mod_1.0.0.zip");
|
||||
const hash = await libHash.hashFile(filePath);
|
||||
const stat = await fs.stat(filePath);
|
||||
const mod = await ModInfo.fromModFile(filePath);
|
||||
assert.deepEqual(
|
||||
mod,
|
||||
new ModInfo({
|
||||
name: "empty_mod",
|
||||
version: "1.0.0",
|
||||
title: "An Empty Mod",
|
||||
author: "Me",
|
||||
description: "An empty mod for testing",
|
||||
factorio_version: "1.1",
|
||||
dependencies: [],
|
||||
filename: "empty_mod_1.0.0.zip",
|
||||
size: stat.size,
|
||||
hash: `sha1:${hash}`,
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user