示例#1
0
    def test_load_config(self):
        daemon = MCRunner(
            config_file=self.config_file.name,
            pid_file=self.pid_file.name
        )

        daemon.load_config()

        assert daemon.log_file == '/var/log/mcrunner/mcrunnerd.log'
        assert daemon.sock_file == '/tmp/mcrunner.sock'

        assert len(daemon.servers) == 2

        survival = daemon.servers['survival']
        creative = daemon.servers['creative']

        assert survival.name == 'survival'
        assert survival.path == '/path/to/server1'
        assert survival.jar == 'spigot.jar'
        assert survival.opts == '-Xms1G -Xmx8G'

        assert creative.name == 'creative'
        assert creative.path == '/path/to/server2'
        assert creative.jar == 'craftbukkit.jar'
        assert creative.opts == '-Xms8G -Xmx16G'
示例#2
0
    def test_create_logger(self):
        daemon = MCRunner(
            config_file=self.config_file.name,
            pid_file=self.pid_file.name
        )

        daemon.load_config()

        with tempfile.NamedTemporaryFile() as f:
            daemon.log_file = f.name
            logger = daemon.create_logger()

        assert isinstance(logger, logging.getLoggerClass())
示例#3
0
    def test_on_exit(self):
        daemon = MCRunner(
            config_file=self.config_file.name,
            pid_file=self.pid_file.name
        )

        daemon.load_config()
        daemon.logger = mock.MagicMock()

        daemon.servers['survival'].stop = mock.MagicMock()
        daemon.servers['creative'].stop = mock.MagicMock()

        daemon.on_exit()

        assert daemon.servers['survival'].stop.call_count == 1
        assert daemon.servers['creative'].stop.call_count == 1
示例#4
0
    def test_get_status(self):
        daemon = MCRunner(
            config_file=self.config_file.name,
            pid_file=self.pid_file.name
        )

        daemon.load_config()

        daemon.servers['survival'].get_status = mock.MagicMock(return_value='some status')
        daemon.servers['creative'].get_status = mock.MagicMock(return_value='some other status')

        status = daemon.get_status()

        assert status[0] is True
        assert 'survival: some status' in status[1]
        assert 'creative: some other status' in status[1]