}); // ======================================================================== // // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { // make sure all the sessions are running first $checkpoint = getCheckpoint(); foreach (hostWithRole('host_target') as $hostId) { foreach ($checkpoint->sessions as $session) { expectsHost($hostId)->screenIsRunning($session); } } foreach (hostWithRole('host_target') as $hostId) { usingHost($hostId)->stopAllScreens(); } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); foreach (hostWithRole('host_target') as $hostId) { foreach ($checkpoint->sessions as $session) { expectsHost($hostId)->screenIsNotRunning($session); } } });
<?php // ======================================================================== // // STORY DETAILS // // ------------------------------------------------------------------------ $story = newStoryFor('Storyplayer')->inGroup('Modules')->called('HTTP: Can connect to self-signed SSL server'); $story->requiresStoryplayerVersion(2); // ======================================================================== // // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { foreach (hostWithRole('ssl_target') as $hostname) { $url = "https://" . fromHost($hostname)->getHostname(); fromHttp()->get($url); } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function ($st) { // do nothing });
if (file_exists($filename)) { // tidy up unlink($filename); } } }); // ======================================================================== // // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { foreach (hostWithRole('upload_target') as $hostname) { fromHost($hostname)->downloadFile('testfile.txt', "/tmp/testfile-{$hostname}.txt"); } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { // we should have a file for each host in the configuration foreach (hostWithRole('upload_target') as $hostname) { $filename = '/tmp/testfile-' . $hostname . '.txt'; if (!file_exists($filename)) { usingLog()->writeToLog("file not downloaded from host '{$hostname}'"); usingErrors()->throwException("file '{$filename}' not downloaded"); } } });
/** * @covers ::hostWithRole */ public function testHostsIteratorThrowsExceptionForUnknownRole() { // ---------------------------------------------------------------- // setup your test // the role to iterate over $rolename = 'test'; // the hostnames that we expect to get $expectedHosts = ['fred', 'alice', 'bob']; // our empty list of hostDetails to iterate over $hosts = new stdClass(); // our fake Prose module to get the hostDetails $fromRolesTable = Mockery::mock("DataSift\\Storyplayer\\Prose\\FromRolesTable"); $fromRolesTable->shouldReceive('getDetailsForRole')->once()->with($rolename)->andReturn($hosts); // our fake $st object $st = Mockery::mock("DataSift\\Storyplayer\\PlayerLib\\StoryTeller"); $st->shouldReceive('startAction')->never(); $st->shouldReceive('fromRolesTable')->once()->andReturn($fromRolesTable); // ---------------------------------------------------------------- // perform the change and test the results $caughtException = false; try { foreach (hostWithRole('test') as $hostname) { $actualHosts[] = $hostname; } } catch (E5xx_ActionFailed $e) { $caughtException = true; } $this->assertTrue($caughtException); }