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

loadExternalResource polish code

上级 1fbecd46
......@@ -50,36 +50,32 @@ 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)
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 {
Log.Debug("http.Get %s Error: %v", resource, err)
return ""
content = string(body)
}
defer resp.Body.Close()
} 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())
Log.Error("os.Open %s Error: %v", resource, err)
return content
}
}()
if err == nil {
defer fd.Close()
body, err = ioutil.ReadAll(fd)
if err != nil {
Log.Debug("ioutil.ReadAll %s Error: %v", resource, err)
Log.Error("ioutil.ReadAll %s Error: %v", resource, err)
} else {
content = string(body)
}
} else {
Log.Debug("os.Open %s Error: %v", resource, err)
}
}
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 ]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册