
Security News
Package Maintainers Call for Improvements to GitHub’s New npm Security Plan
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
gopkg.in/nowk/go-netmock.v0
http.Client
mocking when you can't control the URL
go get gopkg.in/nowk/go-netmock.v0
You use a http.DefaultClient
mapped interface.
type SomeApi struct {
HTTPClient HTTPClient
}
func (s SomeApi) GetSomeApiRequest() (*http.Response, error) {
return s.HTTPClient.Get("http://example.com")
}
Pass your mock in your tests.
func TestRequest(t *testing.T) {
mock := netmock.NewMock(t)
mock.Expect("GET", "http://example.com").Respond(200, "Hello World!")
api := &SomeApi{mock.HTTPClient}
res, _ := api.GetSomeApiRequest()
if code := res.StatusCode; code != 200 {
t.Errorf("Expected 200, got %d", code)
}
}
mock.Expect("GET", "http://example.com").Respond(200, "Hello World!")
With a regexp
reg := regexp.MustCompile(`http:\/\/example\.com\/foo`)
mock.Expect("GET", reg).Respond(200, "Hello World!")
res, _ := mock.Expect("GET", "http://example.com").Respond(200, `{"foo": "bar"}`)
res.Header.Add("Content-Type", "application/json")
_, mr := mock.Expect("GET", "http://example.com").Respond(200, "Hello World!")
Number of times called
mr.Called(1).Times()
Request Body
mr.Body().Equals("Hello World!")
Request Header
mr.Header("Content-Type").Equals("application/json")
Form values
mr.Form("foo").Equals("bar")
PostForm values
mr.PostForm("baz").Equals("qux")
MIT
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.