golang-lib/web/request_test.go

27 lines
509 B
Go
Raw Permalink 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 {
2021-09-10 23:52:30 +02:00
IP string `json:"query"`
2021-06-23 15:00:03 +02:00
}{}
2021-09-10 23:52:30 +02:00
err := JSONRequest("http://ip-api.com/json/?fields=query", &data)
2021-06-23 15:00:03 +02:00
assert.NoError(err)
assert.NotEqual("", data.IP)
wrongData := ""
2021-09-10 23:52:30 +02:00
err = JSONRequest("http://ip-api.com/json/?fields=query", &wrongData)
2021-06-23 15:00:03 +02:00
assert.Error(err)
wrongData = ""
err = JSONRequest("http://no.example.org/", &wrongData)
assert.Error(err)
}