golang-lib/web/request_test.go

27 lines
480 B
Go
Raw Normal View History

2021-06-23 15:00:03 +02:00
package web
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestJSONRequest(t *testing.T) {
assert := assert.New(t)
data := struct {
IP string `json:"ip"`
}{}
err := JSONRequest("http://ip.jsontest.com/", &data)
assert.NoError(err)
assert.NotEqual("", data.IP)
wrongData := ""
err = JSONRequest("http://ip.jsontest.com/", &wrongData)
assert.Error(err)
wrongData = ""
err = JSONRequest("http://no.example.org/", &wrongData)
assert.Error(err)
}