fix logf, add unit test as an example

This commit is contained in:
Benny~ 2020-05-23 01:02:08 +08:00
parent acb020fb7a
commit e902d2e5d2
No known key found for this signature in database
GPG Key ID: 6CD0DBDA5235D481
2 changed files with 18 additions and 2 deletions

16
helper_test.go Normal file
View File

@ -0,0 +1,16 @@
package main
import (
"testing"
)
// test this file: go test helper_test.go helper.go -v
// test one function: go test -run TestGetFileContentType helper_test.go helper.go -v
func TestGetFileContentType(t *testing.T) {
var zero = []byte("hello")
r := GetFileContentType(zero)
if r != "text/plain; charset=utf-8" {
t.Errorf("Test error for %s", t.Name())
}
}

View File

@ -15,7 +15,7 @@ import (
func autoUpdate() { func autoUpdate() {
defer func() { defer func() {
if err := recover(); err != nil { if err := recover(); err != nil {
log.Errorf("Download error.", err) log.Errorf("Download error: %s", err)
} }
}() }()
@ -45,7 +45,7 @@ func autoUpdate() {
log.Info("Downloading binary to update...") log.Info("Downloading binary to update...")
resp, _ := http.Get(releaseUrl) resp, _ := http.Get(releaseUrl)
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
log.Debug("%s-%s not found on release.", runtime.GOOS, runtime.GOARCH) log.Debugf("%s-%s not found on release.", runtime.GOOS, runtime.GOARCH)
return return
} }
data, _ := ioutil.ReadAll(resp.Body) data, _ := ioutil.ReadAll(resp.Body)