1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-03-01 00:35:28 +08:00

refactor: rewrite all unit test functions with assert

This commit is contained in:
dudaodong
2022-01-09 15:57:21 +08:00
parent 49f62c3550
commit 52c5a91606
2 changed files with 10 additions and 15 deletions

View File

@@ -8,7 +8,7 @@ import (
) )
func TestGetInternalIp(t *testing.T) { func TestGetInternalIp(t *testing.T) {
assert := internal.NewAssert(t, "TestBefore") assert := internal.NewAssert(t, "TestGetInternalIp")
internalIp := GetInternalIp() internalIp := GetInternalIp()
ip := net.ParseIP(internalIp) ip := net.ParseIP(internalIp)

View File

@@ -2,7 +2,6 @@ package netutil
import ( import (
"encoding/json" "encoding/json"
"fmt"
"io/ioutil" "io/ioutil"
"log" "log"
"testing" "testing"
@@ -23,7 +22,7 @@ func TestHttpGet(t *testing.T) {
} }
body, _ := ioutil.ReadAll(resp.Body) body, _ := ioutil.ReadAll(resp.Body)
fmt.Println("response: ", resp.StatusCode, string(body)) t.Log("response: ", resp.StatusCode, string(body))
} }
func TestHttpPost(t *testing.T) { func TestHttpPost(t *testing.T) {
@@ -44,7 +43,7 @@ func TestHttpPost(t *testing.T) {
t.FailNow() t.FailNow()
} }
body, _ := ioutil.ReadAll(resp.Body) body, _ := ioutil.ReadAll(resp.Body)
fmt.Println("response: ", resp.StatusCode, string(body)) t.Log("response: ", resp.StatusCode, string(body))
} }
func TestHttpPut(t *testing.T) { func TestHttpPut(t *testing.T) {
@@ -66,7 +65,7 @@ func TestHttpPut(t *testing.T) {
t.FailNow() t.FailNow()
} }
body, _ := ioutil.ReadAll(resp.Body) body, _ := ioutil.ReadAll(resp.Body)
fmt.Println("response: ", resp.StatusCode, string(body)) t.Log("response: ", resp.StatusCode, string(body))
} }
func TestHttpPatch(t *testing.T) { func TestHttpPatch(t *testing.T) {
@@ -88,7 +87,7 @@ func TestHttpPatch(t *testing.T) {
t.FailNow() t.FailNow()
} }
body, _ := ioutil.ReadAll(resp.Body) body, _ := ioutil.ReadAll(resp.Body)
fmt.Println("response: ", resp.StatusCode, string(body)) t.Log("response: ", resp.StatusCode, string(body))
} }
func TestHttpDelete(t *testing.T) { func TestHttpDelete(t *testing.T) {
@@ -99,22 +98,18 @@ func TestHttpDelete(t *testing.T) {
t.FailNow() t.FailNow()
} }
body, _ := ioutil.ReadAll(resp.Body) body, _ := ioutil.ReadAll(resp.Body)
fmt.Println("response: ", resp.StatusCode, string(body)) t.Log("response: ", resp.StatusCode, string(body))
} }
func TestConvertMapToQueryString(t *testing.T) { func TestConvertMapToQueryString(t *testing.T) {
assert := internal.NewAssert(t, "TestConvertMapToQueryString")
var m = map[string]interface{}{ var m = map[string]interface{}{
"c": 3, "c": 3,
"a": 1, "a": 1,
"b": 2, "b": 2,
} }
assert.Equal("a=1&b=2&c=3", ConvertMapToQueryString(m))
expected := "a=1&b=2&c=3"
r := ConvertMapToQueryString(m)
if r != expected {
internal.LogFailedTestInfo(t, "ConvertMapToQueryString", m, expected, r)
t.FailNow()
}
} }
func TestParseResponse(t *testing.T) { func TestParseResponse(t *testing.T) {
@@ -142,5 +137,5 @@ func TestParseResponse(t *testing.T) {
log.Fatal(err) log.Fatal(err)
t.FailNow() t.FailNow()
} }
fmt.Println("response: ", toDoResp) t.Log("response: ", toDoResp)
} }