fetchall: move multiple-urls subtest to separate test and actually check that each url is hit.
This commit is contained in:
parent
ff40c140ba
commit
91f9796dad
1 changed files with 32 additions and 14 deletions
|
@ -59,20 +59,6 @@ func TestFetchall_valid(t *testing.T) {
|
|||
},
|
||||
queries: []endpoint{"/"},
|
||||
},
|
||||
{
|
||||
name: "multiple-urls",
|
||||
h: func(w http.ResponseWriter, r *http.Request) {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/foo", func(w http.ResponseWriter, h *http.Request) {
|
||||
_, _ = w.Write([]byte("foo"))
|
||||
})
|
||||
mux.HandleFunc("/bar", func(w http.ResponseWriter, h *http.Request) {
|
||||
_, _ = w.Write([]byte("bar"))
|
||||
})
|
||||
mux.ServeHTTP(w, r)
|
||||
},
|
||||
queries: []endpoint{"/foo", "/bar"},
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
s := httptest.NewServer(tc.h)
|
||||
|
@ -92,6 +78,38 @@ func TestFetchall_valid(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestFetchall_multipleURLs(t *testing.T) {
|
||||
binary, err := binCache.GetBinary(fetchallImportPath)
|
||||
require.Nil(t, err)
|
||||
|
||||
var fooHit, barHit int32
|
||||
|
||||
h := func(w http.ResponseWriter, r *http.Request) {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/foo", func(w http.ResponseWriter, h *http.Request) {
|
||||
atomic.StoreInt32(&fooHit, 1)
|
||||
_, _ = w.Write([]byte("foo"))
|
||||
})
|
||||
mux.HandleFunc("/bar", func(w http.ResponseWriter, h *http.Request) {
|
||||
atomic.StoreInt32(&barHit, 1)
|
||||
_, _ = w.Write([]byte("bar"))
|
||||
})
|
||||
mux.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
s := httptest.NewServer(http.HandlerFunc(h))
|
||||
defer s.Close()
|
||||
|
||||
cmd := exec.Command(binary, s.URL+"/foo", s.URL+"/bar")
|
||||
cmd.Stdout = nil
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
require.Nil(t, cmd.Run())
|
||||
|
||||
require.Equal(t, int32(1), atomic.LoadInt32(&fooHit))
|
||||
require.Equal(t, int32(1), atomic.LoadInt32(&barHit))
|
||||
}
|
||||
|
||||
func TestFetchall_malformed(t *testing.T) {
|
||||
binary, err := binCache.GetBinary(fetchallImportPath)
|
||||
require.Nil(t, err)
|
||||
|
|
Loading…
Reference in a new issue