提交 48b2e0fe 编写于 作者: martianzhang's avatar martianzhang

loadExternalResource polish code

上级 1fbecd46
......@@ -50,35 +50,31 @@ func loadExternalResource(resource string) string {
var body []byte
if strings.HasPrefix(resource, "http") {
resp, err := http.Get(resource)
if err == nil {
body, err = ioutil.ReadAll(resp.Body)
if err == nil {
content = string(body)
} else {
Log.Debug("ioutil.ReadAll %s Error: %v", resource, err)
}
} else {
Log.Debug("http.Get %s Error: %v", resource, err)
return ""
if err != nil {
Log.Error("http.Get %s Error: %v", resource, err)
return content
}
defer resp.Body.Close()
body, err = ioutil.ReadAll(resp.Body)
if err != nil {
Log.Error("ioutil.ReadAll %s Error: %v", resource, err)
} else {
content = string(body)
}
} else {
fd, err := os.Open(resource)
defer func() {
err = fd.Close()
if err != nil {
Log.Error("loadExternalResource(%s) fd.Close failed: %s", resource, err.Error())
}
}()
if err == nil {
body, err = ioutil.ReadAll(fd)
if err != nil {
Log.Debug("ioutil.ReadAll %s Error: %v", resource, err)
} else {
content = string(body)
}
if err != nil {
Log.Error("os.Open %s Error: %v", resource, err)
return content
}
defer fd.Close()
body, err = ioutil.ReadAll(fd)
if err != nil {
Log.Error("ioutil.ReadAll %s Error: %v", resource, err)
} else {
Log.Debug("os.Open %s Error: %v", resource, err)
content = string(body)
}
}
return content
......
......@@ -77,8 +77,6 @@ load test_helper
@test "Check soar report for html" {
${SOAR_BIN} -query "select * from film" \
-report-title "soar report check" \
-report-javascript "https://cdn.bootcss.com/twitter-bootstrap/3.4.0/js/npm.js" \
-report-css "https://cdn.bootcss.com/twitter-bootstrap/3.4.0/css/bootstrap-theme.css" \
-report-type html > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
run golden_diff
[ $status -eq 0 ]
......@@ -139,4 +137,4 @@ run ${SOAR_BIN} -online-dsn="root:pase@D@192.168.12.11:3306/testDB" -print-confi
run ${SOAR_BIN_ENV} -query "select * from film" -log-level=7
[ $(expr "$output" : ".*1tIsB1g3rt.*") -eq 0 ]
[ ${status} -eq 0 ]
}
\ No newline at end of file
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册