19 #include <CUnit/CUnit.h> 20 #include "wget_agent.h" 21 #include "../utility.h" 24 #include "libfodbreposysconf.h" 26 #define AGENT_DIR "../../" 34 static PGresult *result = NULL;
46 char TempFileDir[STRMAX];
47 char TempFile[STRMAX];
50 dbManager = createTestEnvironment(AGENT_DIR,
"wget_agent", 1);
52 LOG_FATAL(
"Unable to connect to database");
56 pgConn = fo_dbManager_getWrappedConnection(dbManager);
60 strcpy(URL,
"https://mirrors.kernel.org/fossology/releases/3.0.0/ubuntu/14.04/");
61 strcpy(TempFileDir,
"./test_result/");
62 strcpy(TempFile,
"./test_result/fossology.sources.list");
63 GetURL(TempFile, URL, TempFileDir);
65 strcpy(
GlobalURL,
"https://mirrors.kernel.org/fossology/releases/3.0.0/ubuntu/14.04/");
68 memset(
SQL,
'\0',STRMAX);
69 snprintf(
SQL,STRMAX,
"DELETE FROM upload where upload_filename = 'fossology.sources.list';");
73 printf(
"Perpare delete information ERROR!\n");
79 memset(
SQL,
'\0',STRMAX);
80 snprintf(
SQL,STRMAX,
"INSERT INTO upload (upload_filename,upload_mode,upload_ts) VALUES ('fossology.sources.list',40,now());");
84 printf(
"Perpare upload information ERROR!\n");
89 memset(
SQL,
'\0',STRMAX);
90 snprintf(
SQL,STRMAX,
"SELECT upload_pk from upload where upload_filename = 'fossology.sources.list';");
94 printf(
"Perpare upload information ERROR!\n");
100 GError* error = NULL;
101 char* foConf = get_confFile();
104 snprintf(cmd, STRMAX,
"sed -i 's|depth.*|depth=3|' %s", foConf);
105 if (system(cmd) != 0) {
106 printf(
"cannot reset depth to 3 with %s\n", cmd);
113 printf(
"cannot load config from '%s' error: %s\n", foConf, error->message);
127 char TempFileDir[STRMAX];
129 strcpy(TempFileDir,
"./test_result");
130 if (file_dir_existed(TempFileDir))
139 char repoDir[STRMAX+1];
144 dropTestEnvironment(dbManager, AGENT_DIR,
"wget_agent");
156 int length = strlen(
string);
158 for (i = 0; i < length; i++)
160 string[i] = tolower(
string[i]);
181 memset(SQL, 0, STRMAX);
183 snprintf(SQL, STRMAX-1,
"select pfile_sha1, pfile_md5 from pfile where pfile_pk in (select pfile_fk from " 185 result = PQexec(
pgConn, SQL);
191 pfile_sha1 = PQgetvalue(result,0,0);
192 pfile_md5 = PQgetvalue(result,0,1);
197 char file_name_file[STRMAX] = {0};
198 char file_name_gold[STRMAX] = {0};
199 char string0[3] = {0};
200 char string1[3] = {0};
201 char string2[3] = {0};
203 strncpy(string0, pfile_sha1, 2);
204 strncpy(string1, pfile_sha1 + 2, 2);
205 strncpy(string2, pfile_sha1 + 4, 2);
207 sprintf(file_name_file,
"%s/repo/files/%s/%s/%s/%s.%s.10240", string4, string0, string1, string2, pfile_sha1, pfile_md5);
208 sprintf(file_name_gold,
"%s/repo/gold/%s/%s/%s/%s.%s.10240", string4, string0, string1, string2, pfile_sha1, pfile_md5);
209 int existed = file_dir_existed(file_name_file);
210 CU_ASSERT_EQUAL(existed, 1);
216 existed = file_dir_existed(file_name_gold);
217 CU_ASSERT_EQUAL(existed, 1);
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
PGconn * pgConn
Database connection.
int RemoveDir(char *dirpath)
Remove all files under dirpath (rm -rf)
long GlobalUploadKey
Input for this system.
char GlobalParam[STRMAX]
Additional parameters.
int GetURL(char *TempFile, char *URL, char *TempFileDir)
Do the wget.
CU_TestInfo testcases_DBLoadGold[]
testcases for function DBLoadGold
char GlobalURL[URLMAX]
URL to download.
void testDBLoadGold()
Function to test DBLoadGold.
int fo_checkPQcommand(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres commands (not select) If an error occured, write the error to s...
int DBLoadGoldClean()
Clean the env.
void DBLoadGold()
Insert a file into the database and repository.
char SQL[256]
SQL query to execute.
char GlobalTempFile[STRMAX]
Temp file to be used.
int DBLoadGoldInit()
initialize
fo_dbManager * dbManager
fo_dbManager object
void fo_config_free(fo_conf *conf)
Frees the memory associated with the internal configuration data structures.
char * get_sysconfdir()
get sysconfig dir path just created by create_db_repo_sysconf()
fo_conf * fo_config_load(char *rawname, GError **error)
Load the configuration information from the provided file.
void string_tolower(char *string)
Convert a string to lower case.
void SafeExit(int rc)
Close scheduler and database connections, then exit.