Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
mirostauder committed Jun 8, 2023
1 parent ed6b5d1 commit 5496aca
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 29 deletions.
34 changes: 14 additions & 20 deletions test/tap/tap/command_line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,58 +112,52 @@ int CommandLine::getEnv() {
std::string dir_path = exe_path.substr(0, exe_path.find_last_of('/'));
std::string dir_name = dir_path.substr(dir_path.find_last_of('/') + 1);

diag("reading: %s", (dir_path + "/.env").c_str());
diag("loading: %s", (dir_path + "/.env").c_str());
env.load_dotenv((dir_path + "/.env").c_str(), true);

diag("reading: %s", (dir_path + "/" + dir_name + ".env").c_str());
diag("loading: %s", (dir_path + "/" + dir_name + ".env").c_str());
env.load_dotenv((dir_path + "/" + dir_name + ".env").c_str(), true);

diag("reading: %s", (exe_path + ".env").c_str());
diag("loading: %s", (exe_path + ".env").c_str());
env.load_dotenv((exe_path + ".env").c_str(), true);
}

value=getenv("TAP_HOST");
if(!value) return -1;
replace_str_field(&this->host, value);
if(value)
replace_str_field(&this->host, value);

value=getenv("TAP_USERNAME");
if(!value) return -1;
replace_str_field(&this->username, value);
if(value)
replace_str_field(&this->username, value);

value=getenv("TAP_PASSWORD");
if(!value) return -1;
replace_str_field(&this->password, value);
if(value)
replace_str_field(&this->password, value);

value=getenv("TAP_ADMINUSERNAME");
if (value) {
if (value)
replace_str_field(&this->admin_username, value);
}

value=getenv("TAP_ADMINPASSWORD");
if (value) {
if (value)
replace_str_field(&this->admin_password, value);
}

int env_port=0;
int env_port = 0;
value=getenv("TAP_PORT");
if(value)
env_port=strtol(value, NULL, 10);
else
env_port=6033;
if(env_port>0 && env_port<65536)
port=env_port;

value=getenv("TAP_ADMINPORT");
if(value)
env_port=strtol(value, NULL, 10);
else
env_port=6032;
if(env_port>0 && env_port<65536)
admin_port=env_port;

value=getenv("TAP_WORKDIR");
if(!value) return -1;
replace_str_field(&this->workdir, value);
if(value)
replace_str_field(&this->workdir, value);

value=getenv("TAP_CLIENT_FLAGS");
if (value) {
Expand Down
4 changes: 2 additions & 2 deletions test/tap/tap/command_line.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class CommandLine {

char* host = strdup("127.0.0.1");
char* username = strdup("root");
char* password = strdup("");
char* password = strdup("root");
char* admin_username = strdup("admin");
char* admin_password = strdup("admin");

int port = 6033;
int admin_port = 6032;
char* workdir = strdup("./tests/");
char* workdir = strdup("./");

uint64_t client_flags = 0;
int getEnv();
Expand Down
13 changes: 6 additions & 7 deletions test/tap/tests/envvars-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,25 @@
#include "tap.h"
#include "command_line.h"

int main() {
int main(int argc, char** argv) {
CommandLine cl;

char* value = NULL;

// this test checks the env file loading mechanism implemented in tap/command_line.cpp:CommandLine::getEnv()
// foldername/.env - enviroment vars for whole folder
// foldername/foldername.env - enviroment vars for whole folder
// foldername/testname-t.env - enviroment vars only for testname-t

// create
// echo 'TAP_ENV_VAR1=.env' > .env
// echo 'TAP_ENV_VAR2=tests.env' > tests.env
// echo 'TAP_ENV_VAR3=envvars-t.env' > envvars-t.env
// echo 'TAP_ENV_VAR4=envvars.env' > envvars.env

// if (cl.getEnv()) {
// diag("Failed to get the required environmental variables.");
// return -1;
// }
cl.getEnv();
if (cl.getEnv()) {
diag("Failed to get the required environmental variables.");
return -1;
}

plan(3);

Expand Down

0 comments on commit 5496aca

Please sign in to comment.