2017-12-04 05:46:34 +00:00
|
|
|
/*
|
|
|
|
Examplar - An automation and testing framework.
|
|
|
|
|
|
|
|
© SURRO INDUSTRIES and Chris Punches, 2017.
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as
|
|
|
|
published by the Free Software Foundation, either version 3 of the
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2017-06-20 06:06:33 +00:00
|
|
|
/* Unit.h
|
|
|
|
* Unit is a type that represents a safely deserialized JSON object which defines what actions are taken as Examplar
|
|
|
|
* iterates through it's Tasks in it's given Plan. They only define the behaviour on execution, while the tasks define
|
|
|
|
* which Units are executed and in what order (and which Units a given Task depends on.
|
|
|
|
*/
|
2017-04-30 05:39:03 +00:00
|
|
|
#ifndef FTESTS_UNIT_H
|
|
|
|
#define FTESTS_UNIT_H
|
|
|
|
#include <string>
|
2020-06-21 00:09:32 +00:00
|
|
|
#include "../../json/json.h"
|
|
|
|
#include "../low_level/JSON_Loader.h"
|
|
|
|
#include "../../Logger/Logger.h"
|
2017-04-30 05:39:03 +00:00
|
|
|
|
2017-06-20 06:06:33 +00:00
|
|
|
class Unit: JSON_Loader
|
2017-04-30 05:39:03 +00:00
|
|
|
{
|
|
|
|
private:
|
2017-06-20 06:06:33 +00:00
|
|
|
// the name of the test
|
2017-04-30 05:39:03 +00:00
|
|
|
std::string name;
|
2017-06-20 06:06:33 +00:00
|
|
|
|
|
|
|
// the path of the executable this test executes when run
|
2017-04-30 05:39:03 +00:00
|
|
|
std::string target;
|
2017-06-20 06:06:33 +00:00
|
|
|
|
|
|
|
// the desired output
|
|
|
|
// poll: would an empty value be good to indicate to rely solely on zero/non-zero exit code?
|
2017-04-30 05:39:03 +00:00
|
|
|
std::string output;
|
2017-06-20 06:06:33 +00:00
|
|
|
|
|
|
|
// the path of the executable this test runs when the target executable fails to produce output or a 0 exit code.
|
2017-04-30 05:39:03 +00:00
|
|
|
std::string rectifier;
|
2017-06-20 06:06:33 +00:00
|
|
|
|
|
|
|
// an indicator of whether the test is active or not
|
|
|
|
// this is used as a way to give definers a way to force executors to edit arbitrary fields or prevent
|
|
|
|
// execution of potentially dangerous or intrusive tests
|
2017-12-02 02:41:22 +00:00
|
|
|
bool active;
|
2017-06-20 06:06:33 +00:00
|
|
|
|
|
|
|
// an indicator of whether or not this test is required to pass.
|
|
|
|
// intended to be used as a flag to halt execution of further tests on failure
|
2017-12-02 02:41:22 +00:00
|
|
|
bool required;
|
2017-06-20 06:06:33 +00:00
|
|
|
|
|
|
|
// indicator of whether the rectifier executable should be run on test failures.
|
|
|
|
// if rectifier exits on non-zero return code, it should be trigger the behaviour indicated by required
|
2017-12-02 02:41:22 +00:00
|
|
|
bool rectify;
|
2017-04-30 05:39:03 +00:00
|
|
|
|
2020-06-29 06:22:11 +00:00
|
|
|
// user to run process as.
|
|
|
|
// not intended for protected accounts, handle your own security
|
|
|
|
std::string user;
|
|
|
|
|
|
|
|
// group to run process as.
|
|
|
|
// not intended for protected accounts, handle your own security
|
|
|
|
std::string group;
|
|
|
|
|
2020-07-02 02:30:51 +00:00
|
|
|
// shell to use for env
|
|
|
|
std::string shell;
|
|
|
|
|
|
|
|
|
2017-04-30 05:39:03 +00:00
|
|
|
public:
|
2020-06-21 00:09:32 +00:00
|
|
|
Unit( int LOG_LEVEL );
|
2017-06-09 03:49:13 +00:00
|
|
|
|
2017-06-20 06:06:33 +00:00
|
|
|
// loads a serialized jason::value object as a unit
|
2017-06-09 03:49:13 +00:00
|
|
|
int load_root( Json::Value loader_root );
|
|
|
|
|
2017-06-20 06:06:33 +00:00
|
|
|
// loads a string as a json string and deserializes that.
|
|
|
|
int load_string( std::string json_val );
|
|
|
|
|
|
|
|
// getters
|
2017-04-30 05:39:03 +00:00
|
|
|
std::string get_name();
|
|
|
|
std::string get_target();
|
|
|
|
std::string get_output();
|
|
|
|
std::string get_rectifier();
|
2017-12-02 02:41:22 +00:00
|
|
|
bool get_active();
|
|
|
|
bool get_required();
|
|
|
|
bool get_rectify();
|
2020-06-29 06:22:11 +00:00
|
|
|
std::string get_user();
|
|
|
|
std::string get_group();
|
2020-07-02 02:30:51 +00:00
|
|
|
std::string get_shell();
|
2020-06-21 00:09:32 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
int LOG_LEVEL;
|
|
|
|
Logger slog;
|
2017-04-30 05:39:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //FTESTS_UNIT_H
|