8 #include <CUnit/CUnit.h>
9 #include "wget_agent.h"
10 #include "../utility.h"
13 #include "libfodbreposysconf.h"
23 static PGresult *result = NULL;
35 char TempFileDir[STRMAX];
36 char TempFile[STRMAX];
39 dbManager = createTestEnvironment(AGENT_DIR,
"wget_agent", 1);
41 LOG_FATAL(
"Unable to connect to database");
45 pgConn = fo_dbManager_getWrappedConnection(dbManager);
49 strcpy(URL,
"https://mirrors.kernel.org/fossology/releases/3.0.0/ubuntu/14.04/");
50 strcpy(TempFileDir,
"./test_result/");
51 strcpy(TempFile,
"./test_result/fossology.sources.list");
52 GetURL(TempFile, URL, TempFileDir);
54 strcpy(
GlobalURL,
"https://mirrors.kernel.org/fossology/releases/3.0.0/ubuntu/14.04/");
57 memset(
SQL,
'\0',STRMAX);
58 snprintf(
SQL,STRMAX,
"DELETE FROM upload where upload_filename = 'fossology.sources.list';");
62 printf(
"Perpare delete information ERROR!\n");
68 memset(
SQL,
'\0',STRMAX);
69 snprintf(
SQL,STRMAX,
"INSERT INTO upload (upload_filename,upload_mode,upload_ts) VALUES ('fossology.sources.list',40,now());");
73 printf(
"Perpare upload information ERROR!\n");
78 memset(
SQL,
'\0',STRMAX);
79 snprintf(
SQL,STRMAX,
"SELECT upload_pk from upload where upload_filename = 'fossology.sources.list';");
83 printf(
"Perpare upload information ERROR!\n");
90 char* foConf = get_confFile();
93 snprintf(cmd, STRMAX,
"sed -i 's|depth.*|depth=3|' %s", foConf);
94 if (system(cmd) != 0) {
95 printf(
"cannot reset depth to 3 with %s\n", cmd);
102 printf(
"cannot load config from '%s' error: %s\n", foConf, error->message);
116 char TempFileDir[STRMAX];
118 strcpy(TempFileDir,
"./test_result");
119 if (file_dir_existed(TempFileDir))
124 char repoDir[STRMAX+1];
129 dropTestEnvironment(dbManager, AGENT_DIR,
"wget_agent");
141 int length = strlen(
string);
143 for (i = 0; i < length; i++)
145 string[i] = tolower(
string[i]);
166 memset(
SQL, 0, STRMAX);
168 snprintf(
SQL, STRMAX-1,
"select pfile_sha1, pfile_md5 from pfile where pfile_pk in (select pfile_fk from "
176 pfile_sha1 = PQgetvalue(result,0,0);
177 pfile_md5 = PQgetvalue(result,0,1);
182 char file_name_file[STRMAX] = {0};
183 char file_name_gold[STRMAX] = {0};
184 char string0[3] = {0};
185 char string1[3] = {0};
186 char string2[3] = {0};
188 strncpy(string0, pfile_sha1, 2);
189 strncpy(string1, pfile_sha1 + 2, 2);
190 strncpy(string2, pfile_sha1 + 4, 2);
192 sprintf(file_name_file,
"%s/repo/files/%s/%s/%s/%s.%s.10240", string4, string0, string1, string2, pfile_sha1, pfile_md5);
193 sprintf(file_name_gold,
"%s/repo/gold/%s/%s/%s/%s.%s.10240", string4, string0, string1, string2, pfile_sha1, pfile_md5);
194 int existed = file_dir_existed(file_name_file);
195 CU_ASSERT_EQUAL(existed, 1);
201 existed = file_dir_existed(file_name_gold);
202 CU_ASSERT_EQUAL(existed, 1);
char SQL[256]
SQL query to execute.
PGconn * pgConn
Database connection.
fo_conf * fo_config_load(char *rawname, GError **error)
Load the configuration information from the provided file.
char * get_sysconfdir()
get sysconfig dir path just created by create_db_repo_sysconf()
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
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...
void testDBLoadGold()
Function to test DBLoadGold.
CU_TestInfo testcases_DBLoadGold[]
testcases for function DBLoadGold
int DBLoadGoldInit()
initialize
void string_tolower(char *string)
Convert a string to lower case.
int DBLoadGoldClean()
Clean the env.
int RemoveDir(char *dirpath)
Remove all files under dirpath (rm -rf)
void SafeExit(int rc)
Close scheduler and database connections, then exit.
char GlobalParam[STRMAX]
Additional parameters.
int GetURL(char *TempFile, char *URL, char *TempFileDir)
Do the wget.
char GlobalURL[URLMAX]
URL to download.
long GlobalUploadKey
Input for this system.
char GlobalTempFile[STRMAX]
Temp file to be used.
void DBLoadGold()
Insert a file into the database and repository.