Skip to content

Commit dfdc3e6

Browse files
authored
Initial code commit v1.0.0
1 parent d6ac9a4 commit dfdc3e6

32 files changed

+2038
-0
lines changed

config.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"io"
6+
"os"
7+
"strings"
8+
)
9+
10+
type Config map[string]string
11+
12+
func ReadConfig(filename string) (Config, error) {
13+
LogInfo.Println("Read config file "+filename)
14+
15+
config := Config{}
16+
if len(filename) == 0 {
17+
return config, nil
18+
}
19+
file, err := os.Open(filename)
20+
if err != nil {
21+
LogError.Println("Failed to open config file "+filename, err)
22+
return nil, err
23+
}
24+
defer file.Close()
25+
26+
reader := bufio.NewReader(file)
27+
28+
for {
29+
line, err := reader.ReadString('\n')
30+
// check if the line has = sign
31+
// and process the line. Ignore the rest.
32+
if equal := strings.Index(line, "="); equal >= 0 {
33+
if key := strings.TrimSpace(line[:equal]); len(key) > 0 {
34+
value := ""
35+
if len(line) > equal {
36+
value = strings.TrimSpace(line[equal+1:])
37+
}
38+
// assign the config map
39+
config[key] = value
40+
}
41+
}
42+
if err == io.EOF {
43+
break
44+
}
45+
if err != nil {
46+
return nil, err
47+
}
48+
}
49+
return config, nil
50+
}

constants.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package main
2+
3+
const (
4+
5+
PROJECT_NAME = "httpGo"
6+
PROJECT_VERSION = "v1.0.0"
7+
PROJECT_ROOT_PATH = "./data/"
8+
PROJECT_PROPERTIES_FILE = "project.properties"
9+
ENV_PROPERTIES_FILE = "env.properties"
10+
CONTENT_LOCATION = "/content/"
11+
REPORTS_LOCATION = "/__reports__/"
12+
REPORT_FILE_NAME = "/testStatusReport.html"
13+
14+
API_BASE_PATH = "/httpGo"
15+
WEB_UI_DEFAULT_PATH = API_BASE_PATH+"/web/index.html"
16+
17+
TC_FILE_EXT = ".xml"
18+
REPORT_FILE_EXT = ".html"
19+
20+
SERVER_DEFAULT_PORT = "9999"
21+
22+
TEST_RUN_ID = "p_test_run_id"
23+
GROUP_PATH = "p_group_path"
24+
25+
SMTP_HOST = "smtp.host"
26+
SMTP_PORT = "smtp.port"
27+
SMTP_USER = "smtp.user"
28+
SMTP_PASS = "smtp.pass"
29+
EMAIL_TO = "report.to.email"
30+
EMAIL_FROM = "report.from.email"
31+
EMAIL_FLAG = "report.email.flag"
32+
33+
TEST_STEP_TYPE_HTTP = "HTTP"
34+
TEST_STEP_TYPE_SSH = "SSH"
35+
TEST_STEP_TYPE_SFTP = "SFTP"
36+
TEST_STEP_TYPE_TIMER = "TIMER"
37+
38+
SUCCESS = "success"
39+
ERROR = "error"
40+
SUCCESS_MSG = "Operation successfull"
41+
ERROR_MSG = "Operation failed"
42+
43+
PARAM_HTTP_STATUS = "http.status"
44+
PARAM_HTTP_CODE = "http.code"
45+
PARAM_HTTP_BODY = "http.body"
46+
PARAM_HTTP_HEAD = "http.header"
47+
PARAM_SSH_STATUS = "ssh.status"
48+
PARAM_SSH_OUTPUT = "ssh.output"
49+
PARAM_SFTP_STATUS = "sftp.status"
50+
51+
)
52+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html><html><head><title>DemoTestProject Test Report</title><style type="text/css">
2+
*{margin:0;padding:0}#wrapper,body,html{height:100%}header{height:50px}.accordion{background-color:#eee;color:#444;cursor:pointer;padding:10px;width:100%;border:none;text-align:left;outline:0;font-size:13px;font-weight:700;transition:.4s;font-family:Cambria;color:#044b6e}.accordion:hover,.active{background-color:#cceef4}.accordion:before{content:'\002B';color:#777;font-weight:700;float:right;margin-left:5px}.active:before{content:"\2212"}.panel{padding:0 18px;background-color:#fff;max-height:0;overflow:hidden;transition:max-height .2s ease-out}blockquote{font:14px/22px normal helvetica,Cambria;margin-top:10px;margin-bottom:10px;margin-left:50px;padding-left:5px;border-left:1px solid #cceef4}input,select,textarea{font-family:Cambria;color:#044b6e}.custom-font{font-family:Cambria;color:#044b6e}.bg-default,.bg-error,.bg-primary,.bg-secondary,.bg-success,.bg-warning{color:#fff;border-radius:2px;text-shadow:0 1px 1px rgba(0,0,0,.2);font-family:Cambria;font-weight:700;padding-left:5px;padding-right:5px}.bg-success{background:#2ecc71}.bg-error{background:#ca3c3c}.bg-warning{background:#df7514}.bg-primary{background:#044b6e}.bg-secondary{background:#42b8dd}.i-xxsmall{font-size:60%}.i-xsmall{font-size:75%}.i-small{font-size:80%}.i-large{font-size:110%}.i-xlarge{font-size:125%}.bg-lg-primary{background-image:linear-gradient(to bottom,#26759e,#133d5b)}.bg-lg-info{background-image:linear-gradient(to bottom,#1ab0ec,#1a92c2)}.tc_details,.tc_hide:target,.tc_show{display:none}.tc_hide:target+.tc_show,.tc_hide:target~.tc_details{display:block}.testgroup_dummy{margin-top:50px;margin-left:50px;padding:12px;border-bottom:1px solid #cceef4}.testgroup_first{margin-top:50px;margin-left:50px;padding:12px;border:1px solid #cceef4}.testgroup{margin-left:50px;padding:12px;border-left:1px solid #cceef4;border-right:1px solid #cceef4;border-bottom:1px solid #cceef4}.testgroup_head{font-family:Cambria;font-size:14px;font-weight:700;color:#044b6e;padding-bottom:12px;cursor:pointer}.testgroup_head_left{width:70%;float:left;font-size:13px}.testgroup_head_right{width:30%;float:right;display:flex;justify-content:flex-end;font-size:12px;font-weight:400}.tc_details_align{margin-left:1%;height:100%;width:96%}.teststep{margin-left:30px;margin-top:5px;font-size:12px}.teststep_desc{font-weight:700}.teststep_content{padding-left:20px}.teststep_fail_content{padding-left:20px;font-weight:700;color:#ec7063}::-webkit-scrollbar{width:8px;height:10px;border-radius:0}::-webkit-scrollbar-track{background:#cceef4;border-radius:0}::-webkit-scrollbar-thumb{width:12px;height:10px;background:#13486d;border:2px solid #cceef4;border-radius:0}
3+
</style></head><body><div id="wrapper" style="font-family: 'Cambria';color: #044B6E"> <header class="bg-lg-info"><div style="padding-top: 20px; padding-left: 42%; font-weight:bolder; font-family:'Courier New'; font-size:15px; color: #F4F6F7; ">DemoTestProject&nbsp;TEST REPORT</div></header><div style="width:80%; height:100%; float:right;margin-left:10%;margin-right:10%;"> <div style="height: 100%; background: white; border-bottom:2px solid #cceef4;margin-top:40px"><div class="testgroup_dummy"></div><div class="testgroup"> <div id="hide_tg0" class="testgroup_head tc_hide"><div class="testgroup_head_left">+&nbsp;<label class="bg-error">TEST GROUP</label>&nbsp;http_demo_group</div><div class="testgroup_head_right">Total&nbsp;<strong>5</strong>&nbsp;test cases (<strong>0PASS/5FAIL</strong>)&nbsp;Execution time&nbsp;11.6922543s</div></div><div id="show_tg0" class="testgroup_head tc_show"><div class="testgroup_head_left">-&nbsp;<label class="bg-error">TEST GROUP</label>&nbsp;http_demo_group</div><div class="testgroup_head_right">Total&nbsp;<strong>5</strong>&nbsp;test cases (<strong>0PASS/5FAIL</strong>)&nbsp;Execution time&nbsp;11.6922543s</div></div><div class="tc_details tc_details_align"><blockquote><div class="accordion"><label class="bg-error">TEST CASE</label>&nbsp;TC0001_Get_api_sample<span style="font-weight: normal">&nbsp;Test case to show the sample GET http api test format</span><span style="float:right; font-weight:normal">Execution time&nbsp;2.3396584s</span></div><div class="panel"><div class="teststep"><span class="bg-error">STEP&nbsp;HTTP</span><span class="teststep_desc">&nbsp;GET user details based on userId</span><p class="teststep_content">REQUEST: http://localhost:9090/app/fetch/profile/uid3456
4+
</p><span class="teststep_fail_content"></span></div></div></blockquote><blockquote><div class="accordion"><label class="bg-error">TEST CASE</label>&nbsp;TC0002_Post_api_sample<span style="font-weight: normal">&nbsp;Test case to show the sample GET http api test format</span><span style="float:right; font-weight:normal">Execution time&nbsp;2.3449916s</span></div><div class="panel"><div class="teststep"><span class="bg-error">STEP&nbsp;HTTP</span><span class="teststep_desc">&nbsp;Create new user</span><p class="teststep_content">REQUEST: http://localhost:9090/app/create/profile
5+
{"name": "test user"}</p><span class="teststep_fail_content"></span></div></div></blockquote><blockquote><div class="accordion"><label class="bg-error">TEST CASE</label>&nbsp;TC0003_Delete_api_sample<span style="font-weight: normal">&nbsp;Test case to show the sample DELETE http api test format</span><span style="float:right; font-weight:normal">Execution time&nbsp;2.3409302s</span></div><div class="panel"><div class="teststep"><span class="bg-error">STEP&nbsp;HTTP</span><span class="teststep_desc">&nbsp;Delete user</span><p class="teststep_content">REQUEST: http://localhost:9090/app/remove/profile/uid3456
6+
</p><span class="teststep_fail_content"></span></div></div></blockquote><blockquote><div class="accordion"><label class="bg-error">TEST CASE</label>&nbsp;TC0004_Put_api_sample<span style="font-weight: normal">&nbsp;Test case to show the sample PUT http api test format</span><span style="float:right; font-weight:normal">Execution time&nbsp;2.3138702s</span></div><div class="panel"><div class="teststep"><span class="bg-error">STEP&nbsp;HTTP</span><span class="teststep_desc">&nbsp;Update user details step</span><p class="teststep_content">REQUEST: http://localhost:9090/app/update/profile
7+
{"id": "uid3456", "name": "updated user"}</p><span class="teststep_fail_content"></span></div></div></blockquote><blockquote><div class="accordion"><label class="bg-error">TEST CASE</label>&nbsp;TC0005_Post_body_from_file_api_sample<span style="font-weight: normal">&nbsp;Test case to show the sample GET http api test format</span><span style="float:right; font-weight:normal">Execution time&nbsp;2.3196123s</span></div><div class="panel"><div class="teststep"><span class="bg-error">STEP&nbsp;HTTP</span><span class="teststep_desc">&nbsp;Create new user</span><p class="teststep_content">REQUEST: http://localhost:9090/app/create/profile
8+
@file=post_body.json</p><span class="teststep_fail_content"></span></div></div></blockquote></div></div><div class="testgroup"> <div id="hide_tg1" class="testgroup_head tc_hide"><div class="testgroup_head_left">+&nbsp;<label class="bg-error">TEST GROUP</label>&nbsp;multi_step_group</div><div class="testgroup_head_right">Total&nbsp;<strong>1</strong>&nbsp;test cases (<strong>0PASS/1FAIL</strong>)&nbsp;Execution time&nbsp;4.6640628s</div></div><div id="show_tg1" class="testgroup_head tc_show"><div class="testgroup_head_left">-&nbsp;<label class="bg-error">TEST GROUP</label>&nbsp;multi_step_group</div><div class="testgroup_head_right">Total&nbsp;<strong>1</strong>&nbsp;test cases (<strong>0PASS/1FAIL</strong>)&nbsp;Execution time&nbsp;4.6640628s</div></div><div class="tc_details tc_details_align"><blockquote><div class="accordion"><label class="bg-error">TEST CASE</label>&nbsp;TC0001_Multi_step_api_sample<span style="font-weight: normal">&nbsp;Test case to show the e2e user test creation and deletion</span><span style="float:right; font-weight:normal">Execution time&nbsp;4.6631137s</span></div><div class="panel"><div class="teststep"><span class="bg-error">STEP&nbsp;HTTP</span><span class="teststep_desc">&nbsp;Create new user</span><p class="teststep_content">REQUEST: http://localhost:9090/app/create/profile
9+
{"name": "test user"}</p><span class="teststep_fail_content"></span></div><div class="teststep"><span class="bg-error">STEP&nbsp;TIMER</span><span class="teststep_desc">&nbsp;Wait for data to synch in db</span><p class="teststep_content"></p><span class="teststep_fail_content"></span></div><div class="teststep"><span class="bg-error">STEP&nbsp;HTTP</span><span class="teststep_desc">&nbsp;GET user details based on userId</span><p class="teststep_content"></p><span class="teststep_fail_content"></span></div><div class="teststep"><span class="bg-error">STEP&nbsp;HTTP</span><span class="teststep_desc">&nbsp;Delete user</span><p class="teststep_content">REQUEST: http://localhost:9090/app/remove/profile/uid3456
10+
</p><span class="teststep_fail_content"></span></div></div></blockquote></div></div><div class="testgroup"> <div id="hide_tg2" class="testgroup_head tc_hide"><div class="testgroup_head_left">+&nbsp;<label class="bg-error">TEST GROUP</label>&nbsp;sftp_demo_group</div><div class="testgroup_head_right">Total&nbsp;<strong>2</strong>&nbsp;test cases (<strong>0PASS/2FAIL</strong>)&nbsp;Execution time&nbsp;30.0162989s</div></div><div id="show_tg2" class="testgroup_head tc_show"><div class="testgroup_head_left">-&nbsp;<label class="bg-error">TEST GROUP</label>&nbsp;sftp_demo_group</div><div class="testgroup_head_right">Total&nbsp;<strong>2</strong>&nbsp;test cases (<strong>0PASS/2FAIL</strong>)&nbsp;Execution time&nbsp;30.0162989s</div></div><div class="tc_details tc_details_align"><blockquote><div class="accordion"><label class="bg-error">TEST CASE</label>&nbsp;TC0001_Sftp_upload_sample<span style="font-weight: normal">&nbsp;Test case to show the sample SFTP remote file operation</span><span style="float:right; font-weight:normal">Execution time&nbsp;15.001939s</span></div><div class="panel"><div class="teststep"><span class="bg-error">STEP&nbsp;SFTP</span><span class="teststep_desc">&nbsp;upload sample file</span><p class="teststep_content"></p><span class="teststep_fail_content">Failed to validate parameter sftp.status</span></div></div></blockquote><blockquote><div class="accordion"><label class="bg-error">TEST CASE</label>&nbsp;TC0002_Sftp_download_sample<span style="font-weight: normal">&nbsp;Test case to show the sample SFTP remote file operation</span><span style="float:right; font-weight:normal">Execution time&nbsp;15.0052617s</span></div><div class="panel"><div class="teststep"><span class="bg-error">STEP&nbsp;SFTP</span><span class="teststep_desc">&nbsp;Step to download the log files via sftp</span><p class="teststep_content"></p><span class="teststep_fail_content">Failed to validate parameter sftp.status</span></div></div></blockquote></div></div><div class="testgroup"> <div id="hide_tg3" class="testgroup_head tc_hide"><div class="testgroup_head_left">+&nbsp;<label class="bg-error">TEST GROUP</label>&nbsp;ssh_demo_group</div><div class="testgroup_head_right">Total&nbsp;<strong>2</strong>&nbsp;test cases (<strong>0PASS/2FAIL</strong>)&nbsp;Execution time&nbsp;30.0152074s</div></div><div id="show_tg3" class="testgroup_head tc_show"><div class="testgroup_head_left">-&nbsp;<label class="bg-error">TEST GROUP</label>&nbsp;ssh_demo_group</div><div class="testgroup_head_right">Total&nbsp;<strong>2</strong>&nbsp;test cases (<strong>0PASS/2FAIL</strong>)&nbsp;Execution time&nbsp;30.0152074s</div></div><div class="tc_details tc_details_align"><blockquote><div class="accordion"><label class="bg-error">TEST CASE</label>&nbsp;TC0001_Ssh_sample<span style="font-weight: normal">&nbsp;Test case to show the sample SSH remote command execution</span><span style="float:right; font-weight:normal">Execution time&nbsp;15.0050644s</span></div><div class="panel"><div class="teststep"><span class="bg-error">STEP&nbsp;SSH</span><span class="teststep_desc">&nbsp;Step to get the content of text file via ssh</span><p class="teststep_content">
11+
</p><span class="teststep_fail_content">Failed to validate parameter ssh.status</span></div></div></blockquote><blockquote><div class="accordion"><label class="bg-error">TEST CASE</label>&nbsp;TC0002_Ssh_with_nodeid_sample<span style="font-weight: normal">&nbsp;Test case to show the sample SSH remote command execution</span><span style="float:right; font-weight:normal">Execution time&nbsp;15.001175s</span></div><div class="panel"><div class="teststep"><span class="bg-error">STEP&nbsp;SSH</span><span class="teststep_desc">&nbsp;Step to get the content of text file via ssh</span><p class="teststep_content">
12+
</p><span class="teststep_fail_content">Failed to validate parameter ssh.status</span></div></div></blockquote></div></div><div class="testgroup"> <div id="hide_tg4" class="testgroup_head tc_hide"><div class="testgroup_head_left">+&nbsp;<label class="bg-success">TEST GROUP</label>&nbsp;timer_demo_group</div><div class="testgroup_head_right">Total&nbsp;<strong>1</strong>&nbsp;test cases (<strong>1PASS/0FAIL</strong>)&nbsp;Execution time&nbsp;10.0113548s</div></div><div id="show_tg4" class="testgroup_head tc_show"><div class="testgroup_head_left">-&nbsp;<label class="bg-success">TEST GROUP</label>&nbsp;timer_demo_group</div><div class="testgroup_head_right">Total&nbsp;<strong>1</strong>&nbsp;test cases (<strong>1PASS/0FAIL</strong>)&nbsp;Execution time&nbsp;10.0113548s</div></div><div class="tc_details tc_details_align"><blockquote><div class="accordion"><label class="bg-success">TEST CASE</label>&nbsp;TC0001_timer_sample<span style="font-weight: normal">&nbsp;Test case to show the sample SSH remote command execution</span><span style="float:right; font-weight:normal">Execution time&nbsp;10.0107197s</span></div><div class="panel"><div class="teststep"><span class="bg-secondary">STEP&nbsp;TIMER</span><span class="teststep_desc">&nbsp;Wait for content to record in the file</span><p class="teststep_content"></p></div></div></blockquote></div></div></div></div></div>
13+
<script>var i,acc=document.getElementsByClassName("accordion");for(i=0;i<acc.length;i++)acc[i].addEventListener("click",function(){this.classList.toggle("active");var e=this.nextElementSibling;e.style.maxHeight?e.style.maxHeight=null:e.style.maxHeight=e.scrollHeight+"px"});var j,testcases=document.getElementsByClassName("testgroup_head");for(j=0;j<testcases.length;j++)testcases[j].addEventListener("click",function(){window.location.hash=this.id});
14+
</script></body></html>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testcase name="TC0001_Get_api_sample" desc="Test case to show the sample GET http api test format">
3+
<variable name="user.id">uid3456</variable>
4+
<variable name="app.source">API</variable>
5+
<teststep type="HTTP" desc="GET user details based on userId">
6+
<method>GET</method>
7+
<url>http://localhost:9090/app/fetch/profile/${user.id}</url>
8+
<header name="source">${app.source}</header>
9+
<header name="user-agent">httpGo Server v1.0.0</header>
10+
<expect name="http.code" check="eq" value="200">api response status code is other than 200 OK</expect>
11+
</teststep>
12+
</testcase>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testcase name="TC0002_Post_api_sample" desc="Test case to show the sample GET http api test format">
3+
<variable name="user.id">uid3456</variable>
4+
<variable name="app.source">API</variable>
5+
<teststep type="HTTP" desc="Create new user">
6+
<method>POST</method>
7+
<url>http://localhost:9090/app/create/profile</url>
8+
<header name="source">${app.source}</header>
9+
<header name="user-agent">httpGo Server v1.0.0</header>
10+
<body>{"name": "test user"}</body>
11+
<extract variable="api.res.status" from="http.body" type="json" value="//status">status parameter not found in the response body</extract>
12+
<extract variable="user.id" from="http.body" type="json" value="//id">status parameter not found in the response body</extract>
13+
<expect name="http.code" check="eq" value="200">api response status code is other than 200 OK</expect>
14+
<expect name="api.res.status" check="not equal" value="success">api operation is not success and returned error response</expect>
15+
<expect name="user.id" check="not empty">user id is not created</expect>
16+
</teststep>
17+
</testcase>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testcase name="TC0003_Delete_api_sample" desc="Test case to show the sample DELETE http api test format">
3+
<variable name="user.id">uid3456</variable>
4+
<variable name="app.source">API</variable>
5+
<teststep type="HTTP" desc="Delete user">
6+
<method>DELETE</method>
7+
<url>http://localhost:9090/app/remove/profile/${user.id}</url>
8+
<header name="source">${app.source}</header>
9+
<header name="user-agent">httpGo Server v1.0.0</header>
10+
<expect name="http.code" check="eq" value="204">api response status code is other than 200 OK</expect>
11+
</teststep>
12+
</testcase>

0 commit comments

Comments
 (0)