gfsmos/noaa_client/noaa_client_test.go

36 lines
664 B
Go
Raw Normal View History

2020-02-26 03:34:17 +00:00
package noaa_client
import (
"github.com/stretchr/testify/assert"
"gopkg.in/h2non/gock.v1"
"io/ioutil"
"log"
"testing"
)
func fakeResponse() string {
b, err := ioutil.ReadFile("../test/KeeneResponse.html") // b has type []byte
if err != nil {
log.Fatal(err)
}
return string(b)
}
func TestFoo(t *testing.T) {
defer gock.Off() // Flush pending mocks after test execution
gock.New("https://www.nws.noaa.gov").
Get("/cgi-bin/mos/getmav.pl").
MatchParam("sta", "KEEN").
Reply(200).
BodyString(fakeResponse())
// Use Client & URL from our local test server
api := API{
"KEEN",
}
body := api.GetDataRaw()
assert.Equal(t, "bob", body)
}