From 91f9796dadda981914e02ad55deb13cdd07d3c5c Mon Sep 17 00:00:00 2001 From: Arseny Balobanov Date: Sat, 15 Feb 2020 17:51:07 +0300 Subject: [PATCH] fetchall: move multiple-urls subtest to separate test and actually check that each url is hit. --- fetchall/main_test.go | 46 ++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/fetchall/main_test.go b/fetchall/main_test.go index 3201f6d..72f9719 100644 --- a/fetchall/main_test.go +++ b/fetchall/main_test.go @@ -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)