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

loadExternalResource polish code

上级 1fbecd46
...@@ -50,36 +50,32 @@ func loadExternalResource(resource string) string { ...@@ -50,36 +50,32 @@ func loadExternalResource(resource string) string {
var body []byte var body []byte
if strings.HasPrefix(resource, "http") { if strings.HasPrefix(resource, "http") {
resp, err := http.Get(resource) resp, err := http.Get(resource)
if err == nil { if err != nil {
body, err = ioutil.ReadAll(resp.Body) Log.Error("http.Get %s Error: %v", resource, err)
if err == nil { return content
content = string(body)
} else {
Log.Debug("ioutil.ReadAll %s Error: %v", resource, err)
} }
defer resp.Body.Close()
body, err = ioutil.ReadAll(resp.Body)
if err != nil {
Log.Error("ioutil.ReadAll %s Error: %v", resource, err)
} else { } else {
Log.Debug("http.Get %s Error: %v", resource, err) content = string(body)
return ""
} }
defer resp.Body.Close()
} else { } else {
fd, err := os.Open(resource) fd, err := os.Open(resource)
defer func() {
err = fd.Close()
if err != nil { 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
} }
}() defer fd.Close()
if err == nil {
body, err = ioutil.ReadAll(fd) body, err = ioutil.ReadAll(fd)
if err != nil { if err != nil {
Log.Debug("ioutil.ReadAll %s Error: %v", resource, err) Log.Error("ioutil.ReadAll %s Error: %v", resource, err)
} else { } else {
content = string(body) content = string(body)
} }
} else {
Log.Debug("os.Open %s Error: %v", resource, err)
}
} }
return content return content
} }
......
...@@ -77,8 +77,6 @@ load test_helper ...@@ -77,8 +77,6 @@ load test_helper
@test "Check soar report for html" { @test "Check soar report for html" {
${SOAR_BIN} -query "select * from film" \ ${SOAR_BIN} -query "select * from film" \
-report-title "soar report check" \ -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 -report-type html > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
run golden_diff run golden_diff
[ $status -eq 0 ] [ $status -eq 0 ]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册