mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 23:04:52 +09:00
Add tests for statistics_exporter plugin
These were already made at the time I ported the plugin but somehow I
forgot to add them to the statistics rework commit (26eefb0) :/.
This commit is contained in:
1 parent
9d2e89ec63
commit
37d8eedc0d
1 file changed
+53
@@ -0,0 +1,53 @@
|
||||
const assert = require('assert').strict;
|
||||
|
||||
const mock = require('../../../test/mock');
|
||||
const instance = require('../instance');
|
||||
const info = require('../info');
|
||||
|
||||
|
||||
describe("statistics_exporter plugin", function() {
|
||||
describe("class InstancePlugin", function() {
|
||||
let instancePlugin;
|
||||
before(async function() {
|
||||
instancePlugin = new instance.InstancePlugin(info, new mock.MockInstance());
|
||||
await instancePlugin.init();
|
||||
});
|
||||
|
||||
describe(".onMetrics()", function() {
|
||||
it("should record statistics", async function() {
|
||||
instancePlugin.instance.server.rconCommandResults.set(
|
||||
'/sc remote.call("statistics_exporter", "export")',
|
||||
JSON.stringify({
|
||||
game_tick: 100,
|
||||
player_count: 3,
|
||||
force_flow_statistics: {
|
||||
player: {
|
||||
item_production_statistics: {
|
||||
input: { "inserter": 10, },
|
||||
output: { "iron-plate": 24, }
|
||||
},
|
||||
}
|
||||
},
|
||||
game_flow_statistics: {
|
||||
pollution_statistics: {
|
||||
input: { "boiler": 2000 },
|
||||
output: { "tree-proxy": 560 },
|
||||
}
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
await instancePlugin.onMetrics();
|
||||
|
||||
assert.equal(instance._instancePlayerCount.labels('7357').get(), 3);
|
||||
assert.equal(instance._instanceGameTicksTotal.labels('7357').get(), 100);
|
||||
assert.equal(instance._instanceForceFlowStatistics.labels(
|
||||
'7357', 'player', 'item_production_statistics', 'input', 'inserter').get(),
|
||||
10);
|
||||
assert.equal(instance._instanceGameFlowStatistics.labels(
|
||||
'7357', 'pollution_statistics', 'input', 'boiler').get(),
|
||||
2000);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user