(t *testing.T)
| 18 | const mirror = "https://geo.mirror.pkgbuild.com/" |
| 19 | |
| 20 | func TestSendRequest(t *testing.T) { |
| 21 | server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { |
| 22 | if req.URL.String() != "/api/submit" { |
| 23 | t.Error("/api/submit was not called") |
| 24 | } |
| 25 | |
| 26 | validateRequest(t, req) |
| 27 | |
| 28 | rw.WriteHeader(http.StatusNoContent) |
| 29 | })) |
| 30 | defer server.Close() |
| 31 | |
| 32 | client := submit.Client{Client: server.Client(), BaseURL: server.URL} |
| 33 | request := &submit.Request{ |
| 34 | Version: submit.Version, |
| 35 | System: submit.System{Architecture: system.X86_64}, |
| 36 | OS: submit.OS{Architecture: system.I686, Id: runtime.GOOS}, |
| 37 | Pacman: submit.Pacman{Packages: []string{"pacman", "linux"}, Mirror: mirror}, |
| 38 | } |
| 39 | err := client.SendRequest(*request) |
| 40 | if err != nil { |
| 41 | t.Error(err) |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | func validateRequest(t *testing.T, req *http.Request) { |
| 46 | if req.Method != http.MethodPost { |
nothing calls this directly
no test coverage detected