Use assert package for tests, much cleaner
Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
+16
-37
@@ -4,8 +4,9 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestLinkServiceOp_Hide(t *testing.T) {
|
||||
@@ -13,35 +14,24 @@ func TestLinkServiceOp_Hide(t *testing.T) {
|
||||
defer teardown()
|
||||
|
||||
mux.HandleFunc("/api/hide", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, http.MethodPost)
|
||||
assert.Equal(t, http.MethodPost, r.Method)
|
||||
|
||||
form := url.Values{}
|
||||
form.Set("id", "1,2,3")
|
||||
|
||||
_ = r.ParseForm()
|
||||
if expect, actual := form, r.PostForm; !reflect.DeepEqual(expect, actual) {
|
||||
t.Fatalf("got unexpected value\nexpect: %s\nactual: %s", Stringify(expect), Stringify(actual))
|
||||
}
|
||||
err := r.ParseForm()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, form, r.PostForm)
|
||||
|
||||
fmt.Fprint(w, `{}`)
|
||||
})
|
||||
|
||||
_, err := client.Link.Hide(ctx)
|
||||
if err == nil {
|
||||
t.Fatal("expected error, got nothing instead")
|
||||
}
|
||||
if expect, actual := `must provide at least 1 id`, err.Error(); expect != actual {
|
||||
t.Fatalf("got unexpected value\nexpect: %s\nactual: %s", Stringify(expect), Stringify(actual))
|
||||
}
|
||||
assert.EqualError(t, err, "must provide at least 1 id")
|
||||
|
||||
res, err := client.Link.Hide(ctx, "1", "2", "3")
|
||||
if err != nil {
|
||||
t.Fatalf("got unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if expect, actual := http.StatusOK, res.StatusCode; expect != actual {
|
||||
t.Fatalf("got unexpected value\nexpect: %s\nactual: %s", Stringify(expect), Stringify(actual))
|
||||
}
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, http.StatusOK, res.StatusCode)
|
||||
}
|
||||
|
||||
func TestLinkServiceOp_Unhide(t *testing.T) {
|
||||
@@ -49,33 +39,22 @@ func TestLinkServiceOp_Unhide(t *testing.T) {
|
||||
defer teardown()
|
||||
|
||||
mux.HandleFunc("/api/unhide", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, http.MethodPost)
|
||||
assert.Equal(t, http.MethodPost, r.Method)
|
||||
|
||||
form := url.Values{}
|
||||
form.Set("id", "1,2,3")
|
||||
|
||||
_ = r.ParseForm()
|
||||
if expect, actual := form, r.PostForm; !reflect.DeepEqual(expect, actual) {
|
||||
t.Fatalf("got unexpected value\nexpect: %s\nactual: %s", Stringify(expect), Stringify(actual))
|
||||
}
|
||||
err := r.ParseForm()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, form, r.PostForm)
|
||||
|
||||
fmt.Fprint(w, `{}`)
|
||||
})
|
||||
|
||||
_, err := client.Link.Unhide(ctx)
|
||||
if err == nil {
|
||||
t.Fatal("expected error, got nothing instead")
|
||||
}
|
||||
if expect, actual := `must provide at least 1 id`, err.Error(); expect != actual {
|
||||
t.Fatalf("got unexpected value\nexpect: %s\nactual: %s", Stringify(expect), Stringify(actual))
|
||||
}
|
||||
assert.EqualError(t, err, "must provide at least 1 id")
|
||||
|
||||
res, err := client.Link.Unhide(ctx, "1", "2", "3")
|
||||
if err != nil {
|
||||
t.Fatalf("got unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if expect, actual := http.StatusOK, res.StatusCode; expect != actual {
|
||||
t.Fatalf("got unexpected value\nexpect: %s\nactual: %s", Stringify(expect), Stringify(actual))
|
||||
}
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, http.StatusOK, res.StatusCode)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user